5

I have been using Windows for a while, and with it there is a feature when you want to upload a photo (for example) to a website, you click on the "Choose File" in Chrome to upload a photo, a "File Explorer" opens, and instead of selecting a file from the hard drive you can paste a URL into the "File Explorer" and press open and it will download the file from the web to your temporary files, and use it to be uploaded.

Is there any way I can do that in Ubuntu 12.10?

Here is the windows example:
Upload from url via File Explorer

muru
  • 207,228

3 Answers3

6

This functionality is implemented by the operating system's Open File dialog. Actually the site or the browser you use doesn't matter because this is operating system specific.

Gnome Open File dialog used in Ubuntu doesn't support this feature, however, the File Open dialog used in KDE is able to open HTTP URLs. I'm not sure what is the situation with support in other other desktop environments that run on Ubuntu.

Sergey
  • 44,353
devius
  • 1,229
1

And an obligatory command-line solution :) In the spirit of this answer: What is the command line equivalent of copying a file to clipboard? I wrote a simple Python script which accepts an URL to a resource as a parameter, downloads the file/page to a temporary location and copies the full file name to the clipboard. All that is left is to open Open File dialog and press Ctrl-V.

The script:

#!/usr/bin/python2

import os, tempfile, argparse, urllib

parser = argparse.ArgumentParser(description="Download a file from an URL, save it as a temporary file and copy a link to the file to clipboard")
parser.add_argument("url", help="The URL of a file to download")
args = parser.parse_args()

filename = tempfile.mktemp()
urllib.urlretrieve(args.url, filename)
os.system("echo %s|xclip  -i -selection clipboard" % filename)
print("File %s has been copied to clipboard, now open a File dialog and press Ctrl-V." % filename)

To use, create a directory called bin in your home directory, put the script there (I named it gimme) and set executable permission on it:

chmod +x ~/bin/gimme

Ahh, and you'll need xclip for it to work:

sudo apt-get install xclip

And here's how to use it:

gimme https://askubuntu.com/questions/228667/upload-file-from-url
File /tmp/tmpFXs7_S has been copied to clipboard, now open a File dialog and press Ctrl-V.
Sergey
  • 44,353
0

I'm not a Python coder, but I did want something like this that uploaded files. I tried Sergey's answer, but it didn't work for Facebook chat (possibly elsewhere, that's just where I tried it).

So I modified it a bit:

#!/usr/bin/python2

import os, tempfile, argparse, urllib, urlparse
from random import randint


parser = argparse.ArgumentParser(description="Download a file from a URL, save it as a temporary file and copy a link to the file to clipboard")
parser.add_argument("url", help="The URL of a file to download")
args = parser.parse_args()
path = urlparse.urlparse(args.url).path
urlext = os.path.splitext(path)[1]
filename = tempfile.mktemp() + urlext
urllib.urlretrieve(args.url, filename)
os.system("echo %s|xclip  -i -selection clipboard" % filename)
print("File %s has been copied to clipboard, now open a File dialog and press Ctrl-V." % filename)

Now it adds the file extension to the temp name, so FB identifies the proper mimetype and treats it appropriately.

muru
  • 207,228