Plupload / flash / Amazon S3 / unique_names

I am working on a plupload implementation using flash to upload files to Amazon S3. I have a file upload on S3 that works fine except for one small problem. The problem is that the "unique_names" parameter is not working. I always get the file in S3 with the original file name. After some debugging, I see that a unique file name is created and passed to Flash SWF for download, but it is never used. Any help would be greatly appreciated.

+3
source share
3 answers

This may help: http://www.plupload.com/punbb/viewtopic.php?pid=4321#p4321

, UploadFile.

, :

        preinit : {

         UploadFile: function(up, file) {
             up.settings.multipart_params.key = 'adjsdlasjdasdas.jpg';
         }
        },

"adjsdlasjdasdas.jpg"; .

+4

https://github.com/moxiecode/plupload/issues/254. . , . , php, , , .

preinit : {

    BeforeUpload : function(up,file){

        // Get the file extension 
        var file_name = file.name;
        var extension = file_name.split(".").pop();

        // Create a random ID
        var new_id = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        var d = new Date();
        var n = d.getTime();
        for( var i=0; i < 10; i++ )
        new_id += possible.charAt(Math.floor(Math.random() * possible.length));

        // Change the name NOTE I use a php variable to create a folder on S3
        up.settings.multipart_params.key = "<?php echo $foldername ?>/"+n+new_id+"."+extension;
        up.settings.multipart_params.Filename = "<?php echo $foldername ?>/"+n+new_id+"."+extension;
        }

},
0

You can check if the file is unique before downloading the file. Here is my code.

UploadFile: function(up, file) {
        pluploadlog('[UploadFile]', file);
        // You can override settings before the file is uploaded
        var filename = file.name;
        file.newname = '01'+ filename ;///add your own function here to create something unique. 
         up.settings.multipart_params = {
                   'key': mybucketsubdirectory + filename, 
                  'Filename': filename, 
                  'acl': 'public-read',
                  'Content-Type': 'image/jpeg',
                  'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',
                  'policy': '<?php echo $policy; ?>',
                  'signature': '<?php echo $signature; ?>'
                };
      },

Then, upload the file.newname file added earlier to the file.

FileUploaded: function(up, file, info) {
          if (file.status == 5){
             console.log(file.newname); // If you need to get back the new unique name
            uploadSuccess(file, info); 
          }else{
            showItemError(file);
          }
        }
0
source

Source: https://habr.com/ru/post/1794045/


All Articles