3

I've been uploading files to the amazon s3 using the javascript library filepicker.io and the implementation works ok, the problem I'm facing now is that when users upload files with white spaces or fancy characters those files are not accessible through http, i was wondering if there is any way to apply some kind of renaming to the file prior the uploading face.

I'm using the pickAndStore method from the filepicker.io api

filepicker.pickAndStore({
  mimetype: ['video/*'],
  services:['COMPUTER', 'DROPBOX', 'GOOGLE_DRIVE', 'BOX', 'URL', 'VIDEO', 'FTP'],
},{location: 's3'},function(fpfiles){
  fpfile = fpfiles[0];
  $('#temp_file_url').val('/' + fpfile.key);
});

Thanks.

Marcos Mercedes
  • 190
  • 2
  • 6

2 Answers2

3

You can specify a "path" parameter in both the filepicker.store() call and filepicker.pickAndStore(), so if you want to specifically strip the whitespace from the filenames but keep the rest the same, the structure would be:

filepicker.pick({...options...}, function(fpfile){
    var new_name = process(fpfile.filename);
    filepicker.store(new_name,
        {path: new_name, filename: new_name}, function(){});
});
brettcvz
  • 2,371
  • 1
  • 13
  • 14
  • Thanks bro, you really help me on this one – Marcos Mercedes May 03 '13 at 18:52
  • This will upload the file both times in your S3 bucket, once during pick, once during store, the callback on store is called slowly, so if your user changes pages in between your file will only exist in filepicker's records and not your database. You could call it after pick, but then you will point to the wrong file. – Gepsens Aug 17 '13 at 14:49
  • I am trying to use this technique, but the onSuccess callback seems to be returning an intermediate promise value of "temp.txt". How do I save a file without having to dramatically alter the filename to a non-human readable format using filepicker.js ? – Michael Pell Jul 25 '14 at 19:07
1

You can also use path on pickAndStore but you won't be able to preprocess the inkblob.

Gepsens
  • 673
  • 4
  • 14