I've been digging into Fine Uploader S3 for 2 weeks now, overall this is a really good plugin.
However, I found one issue which I still haven't been able to overcome. I'm not sure if this is a plugin limitation or plain stupidity from my end.
I need to use this method. This is a method where I can set some custom parameters to shoot over to my server after a successful upload to Amazon S3:
var params = {
file_storage: 's3',
file_module: 'gallery',
file_path: $gallery_upload.fineUploaderS3('getKey', id),
file_name: name,
file_type: $gallery_upload.fineUploader('getFile', id).type
};
$gallery_upload.fineUploader('setUploadSuccessParams', params, id);
There are 2 problems:
(1) This is asynchronous, and runs completely on a separate thread as the actual algorithm that fires out the "success" message.
(2) Depending on different places, the "getKey" method returns undefined. This is understandable, but I want the "one place" that getKey() will ALWAYS return that evil key I got from S3.
===========================================================
So ends up that I've got nowhere to place my snippet. I've tried a few places:
(A) Submitted callback
.on('submitted', function(event, id, name){
Nope. As expected, the getKey is not ready yet.
(B) "statusChange" callback @ newStatus == "upload successful".
.on('statusChange', function(event, id, oldStatus, newStatus){
This works sometimes, and sometimes not. Due to asynchronous issue. Also, quite hacky. Looks like this.
.on('statusChange', function(event, id, oldStatus, newStatus){
console.log('Event: statusChange', oldStatus, newStatus);
if( newStatus === 'upload successful' )
{
var params = {
file_storage: 's3',
file_module: 'gallery',
file_path: $gallery_upload.fineUploaderS3('getKey', id),
file_name: name,
file_type: $gallery_upload.fineUploader('getFile', id).type
};
}
})
(C) Progress callback only @ "uploadedBytes == totalBytes"
.on('progress', function(event, id, name, uploadedBytes, totalBytes){
ONLY WHEN uploadedBytes == totalBytes. But again, this sounds dangerous due to the asyncrhonous thing. It's also quite hacky.
(D) Progress callback
.on('progress', function(event, id, name, uploadedBytes, totalBytes){
This seems to work the best, but, it sounds extremely hacky. It's spamming the setUploadSuccessParams() so it's really bad! I was wondering if there is a "correct way" to do this. For example, some bang-on event that works immediately.
Aucun commentaire:
Enregistrer un commentaire