0

I'd like to use jQueryFileUpload to upload a file that is not on my computer but rather is at an external website so all I have is its URL, e.g., https://dl.dropboxusercontent.com/s/wkfr8d04dhgbd86/onarborLogo64.png.

I'm at a total loss on how to do this but I think it involves adding the file data programmatically rather than using the traditional <label for='myComputerFiles'>-based selection of files.

If this is correct, what next FileReader()?

Any thoughts would be appreciated.

tim peterson
  • 23,653
  • 59
  • 177
  • 299
  • You should do this on the server - it requires user intervention to download it locally, and that just seems hacky and unfriendly. – Reinstate Monica Cellio Sep 12 '13 at 16:34
  • @Archer thanks for your thoughts. The real scenario is to use [Dropbox Chooser](https://www.dropbox.com/developers/dropins/chooser/js) so there would be explicit user intervention to "choose" the files from one's own Dropbox. Also, jQueryFileUpload already uses `FileReader()` to give a preview of files selected by ` – tim peterson Sep 12 '13 at 16:51
  • 1
    I understand what you're asking, but I honestly believe this is best done on the server. Reason? You would have to first download the file (which is an indeterminate process), and then upload it to the server. If you pass the URL to the server then it can perform the whole process in 1 action - a download (which is effectively the same as you uploading it). Also, the ability to read local files, which is what FileReader is for, does not mean you should download files to just upload them again. That's bad logic and your users will not appreciate it. – Reinstate Monica Cellio Sep 12 '13 at 16:59
  • Also, Dropbox Chooser is not meant to be a way to download files. It's meant to be a replacement for downloading file, or uploading them to other servers... `...without having to worry about the complexities of implementing a file browser, authentication, or managing uploads and storage` – Reinstate Monica Cellio Sep 12 '13 at 17:01
  • @Archer thanks again. This sounds like a good answer. Though, now I'm thinking I should just use CORS to upload directly to my S3 (the ultimate destination) and skip my own server. In this case, then I use FileReader(), right? – tim peterson Sep 12 '13 at 17:48
  • 1
    If there is an API call on S3 that allows you to specify a URL then that would be the most obvious thing to use. If you can't do that then you either need to download the file *for* the user (onto your server) and then upload the file to S3, or you're back to the original idea of downloading at the client and uploading from there. Either way, the introduction of S3 obviously adds another layer of complication, but I'd initially look at getting a URL from the client and getting that file on my server so I could do anything I wanted after that. – Reinstate Monica Cellio Sep 12 '13 at 18:09
  • Have a look at this previous question... http://stackoverflow.com/questions/10491025/how-to-upload-files-directly-to-amazon-s3-from-a-remote-server – Reinstate Monica Cellio Sep 12 '13 at 18:10
  • Thanks again @Archer you've been super helpful. I'd be happy to upvote your comments if you'd convert it to an answer. – tim peterson Sep 12 '13 at 18:44
  • No worries Tim - I'm happy to help :) – Reinstate Monica Cellio Sep 12 '13 at 18:47

1 Answers1

2

You should do this on the server - it requires user intervention to download it locally, and that just seems hacky and unfriendly.

Reason? You would have to first download the file (which is an indeterminate process), and then upload it to the server. If you pass the URL to the server then it can perform the whole process in 1 action - a download (which is effectively the same as you uploading it). Also, the ability to read local files, which is what FileReader is for, does not mean you should download files to just upload them again. That's bad logic and your users will not appreciate it.

Also, Dropbox Chooser is not meant to be a way to download files. It's meant to be a replacement for downloading file, or uploading them to other servers... ...without having to worry about the complexities of implementing a file browser, authentication, or managing uploads and storage.

Since you're using S3, if there is an API call on S3 that allows you to specify a URL then that would be the most obvious thing to use. If you can't do that then you either need to download the file for the user (onto your server) and then upload the file to S3, or you're back to the original idea of downloading at the client and uploading from there. Either way, the introduction of S3 obviously adds another layer of complication, but I'd initially look at getting a URL from the client and getting that file on my server so I could do anything I wanted after that.

This previous question may be of some help in this area...

How to upload files directly to Amazon S3 from a remote server?

Community
  • 1
  • 1
Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67