1

filepicker.pick() 将文件存储在 S3(根目录)上。如果我稍后调用 filepicker.store() 那么文件将被复制到新位置,所以最后我在两个不同的位置使用两个不同的文件名有两次相同的文件。如何避免这种情况?

我想分别选择两个文件,然后在处理我的表单时立即将它们上传到 S3。

  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
  });
4

2 回答 2

2

为了在使用 filepicker.pick 并从您的计算机上传时返回 FPFile 对象上的 url,我们必须将文件上传到 S3。对于 Facebook 等其他服务,我们不会将文件传输到 S3,而只是为您提供一个直接解析回 Facebook 文件的 URL。

如果需要,您可以使用 filepicker.pickAndStore,它会自动解决这个问题,或者使用 filepicker.remove() 调用。

于 2013-05-03T02:02:40.447 回答
1

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')
        });

    });

});
于 2015-03-27T22:36:42.623 回答