Reputation: 54949
Here's what my file picker looks like
filepicker.pick({
mimetypes: ['image/*'],
services: ['COMPUTER', 'URL'],
maxSize: 5 * 1000 * 1024
}, function(FPFile) {
// do stuff to file
});
The problem is that when a url select is chosen, instead of uploading the file to file picker the url is served directly. This makes storage unreliable because the external host can take the file down, etc.
Is there a simple way to ensure that when using the URL upload the file is directly hosted?
Upvotes: 0
Views: 472
Reputation: 695
There are two options for this.
The first of which is the Store API. When you receive the fpurl back, call the store
api and this will save the file to your storage directly. This might be best if, for example, people can select files at will, but you only want to persist them when they choose to save something. e.g. when uploading for a new post. Why persist items if they don't decide to create a new post in the end?
https://developers.filepicker.io/docs/web/#store
The second option is to replace your pick
call, with the pickAndStore
call, which does both at once and saves you having to do the store
command in your pick
callback.
https://developers.filepicker.io/docs/web/#pickAndStore
While pickAndStore
may feel like it saves work, if there's a chance that you don't actualy need to persist data after a user picks it, then I'd go the extra distance with your own custom callbacks (this is where you'd create difference conversions too).
Upvotes: 1
Reputation: 2381
The best way is to use the filepicker.store api - see https://developers.filepicker.io/docs/web/#store for more information
Upvotes: 0