Reputation: 3784
filepicker.pick() store file on S3 (root directory). If I later call filepicker.store() then file will be copied to new location so at the end I have the same file twice in two different locations with two different filenames. How to avoid this?
I would like select two files separately, then upload them to S3 at once when my form is processed.
filepicker.pick({container: "modal"}, function(fpfile) {
alert("picked"); //file is stored on S3
filepicker.store(fpfile, { location: "S3", path: "tmp/"}); //will copy to "tmp/" location
});
Upvotes: 1
Views: 373
Reputation: 9121
You are right - if you have S3 configured then you will end up with 2 files if you do pick() and then store() afterwards.
The file that is created by pick() will be on the root level of your S3 bucket.
I didn't find a way to avoid that, so I ran with pick(), store() and remove() - as those are async functions you need to nest them, or (better) use the flow control of your choice.
If you don't need to do anything between pick() and store() then you could do pickAndStore(), if you need information from the pick() call before doing the store() request, go with the example below:
var file;
// authenticate
filepicker.setKey('YOUR_API_KEY');
// pick
filepicker.pick({
container : 'modal',
debug : false,
extensions : ['.png', '.jpg', '.jpeg', '.gif'],
folders : false,
language : 'en',
maxFiles : 1,
maxSize : '2560*1600',
multiple : false,
openTo : 'COMPUTER',
services : [
'BOX',
'COMPUTER'
]
}, function(res) {
// save blob, to remove it later
file = res;
// store
filepicker.store(file, {
access : 'public',
container : 'YOUR_BUCKET',
location : 'S3',
path : 'SOME_FOLDER/ANOTHER_FOLDER/FILENAME.png'
}, function(res) {
// remove
filepicker.remove(file, function() {
console.log('ok')
});
});
});
Upvotes: 1
Reputation: 2381
In order to give you back a url on the FPFile object when using filepicker.pick and uploading from your computer, we have to upload the file onto S3. For other services like Facebook, we don't transfer the file to S3, instead just give you a URL that resolves directly back to the Facebook file.
If you want, you can either use filepicker.pickAndStore, which resolves this automatically, or use the filepicker.remove() call.
Upvotes: 2