Upload a image to a website without downloading that image
Windows has a feature where when we paste a direct image link ( xxx.com/xxx.jpg ) in the "file name" input field of the upload file explorer (the small window that pops up when we click "Choose file"/"Upload" on any website) the image is downloaded automatically (as a temp file) and uploaded.
You don't have to save the image, then upload it somewhere...
Is there any way to achieve the same thing in macOS?
This question has been asked previously:
Upload file via URL
Upload file directly from a URL in upload (File/Open) dialog
However the answers are quite dated. Maybe this feature has been implemented now?
Solution 1:
Unfortunately, I think the short answer to your question is no, this is still not (reasonably) possible on macOS. The simplest approach still seems to be to download the image, upload it, and then delete it. This is probably the approach I would personally take. However…
If you are truly desperate to find a way to download a temporary file from the file dialog, there is technically a way to do it, although I don't think there's any practical use case for this approach. But, if as nothing else than a proof of concept, here's what I pieced together. (This will work without any additional setup on macOS Catalina and later; earlier versions will require a manual installation of Python 3.)
The basic premise of the approach is to use a file name as a URL input. That is, you enter the URL you want as the name of a file (which, thankfully, can be quite long on APFS) in a special location on disk, and a script will automatically temporarily download the correct resource from the web into the same directory for you to insert. (Note one important caveat: the URL must not contain any colons, since macOS can't handle those in file names. Crucially, this means you'll have to omit the http://
or https://
portion of URLs when typing/pasting them.)
Here's how to implement this:
-
Open System Preferences and go to Security & Privacy > Privacy > Full Disk Access. Click the padlock in the lower left to unlock the pane. Then, in Finder, navigate to
/usr/bin/
, and drag thepython3
icon into the list in System Preferences. Make sure the checkbox next topython3
is checked. -
Save the following as
com.badidea.url-file-watcher.plist
in~/Library/LaunchAgents
. Replace[PATH TO PYTHON SCRIPT]
with the absolute path to the Python script you'll create later on (I put mine at/Users/[myusername]/Documents/fetchurl.py
). Also replace[PATH TO WATCHED FOLDER]
with a relative or absolute path to the folder where you'll put the "magic file" (I chose~/Desktop/filefromurl/
):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>url-file-watcher</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>[PATH TO PYTHON SCRIPT]</string>
</array>
<key>WatchPaths</key>
<array>
<string>[PATH TO WATCHED FOLDER]</string>
</array>
</dict>
</plist>
- Create the Python file at the path you selected in step 2 (again, in my example, this would be at
~/Documents/fetchurl.py
), and paste the following code:
import os
import time
from urllib.parse import urlparse, unquote
from urllib.request import urlretrieve
from pathlib import Path
def main():
dir_path = os.path.expanduser('~/Desktop/filefromurl')
files = os.listdir(dir_path)
if '.DS_Store' in files:
files.remove('.DS_Store')
url_from_file = files[0].replace(':', '/')
if url_from_file == 'url':
return
file_name = unquote(os.path.basename(urlparse(url_from_file).path))
file_name.replace(':', '_')
file_name.replace('/', ':')
try:
urlretrieve('https://' + url_from_file, os.path.join(dir_path, file_name))
except:
try:
urlretrieve('http://' + url_from_file, os.path.join(dir_path, file_name))
except:
return
os.remove(os.path.join(dir_path, files[0]))
time.sleep(10) # customize as desired -- # of seconds to wait before deleting temp file (can't use again until it's deleted)
for file in os.listdir(dir_path):
os.remove(os.path.join(dir_path, file))
Path(os.path.join(dir_path, 'url')).touch()
main()
-
Create the "watched folder" you entered in step 2. (In my example, this is
~/Desktop/filefromurl
.) Then open the Terminal and typetouch [PATH TO WATCHED FOLDER]/url
, replacing[PATH TO WATCHED FOLDER]
with the relative or absolute path to your "watched folder" that you created. (So for me, this would betouch ~/Desktop/filefromurl/url
.) -
In the Terminal, run
launchctl load ~/LaunchAgents/com.badidea.url-file-watcher.plist
. -
Now, when you want to upload a file in your browser, simply navigate to your "watched folder" (I would put it in your Finder sidebar for convenience) and then change the name of the
url
file to the URL you want to download (again, withouthttp(s)://
). After a moment, you'll see the downloaded file appear in the file browser, and you'll have ten seconds (the delay can be customized on line 30 of the Python script) to select and upload the file, after which time the temporary file will be automatically deleted and replaced with the placeholderurl
file for next time.
And just to prove it all (technically) works, here's a brief demonstration: