Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

ajax - DropzoneJs: How to manually send an actual file to a server (on removedfile)?

I am using DropzoneJs and I want to send a removed file to a server. Unlike many other solutions posted here, I need to send an actual file as it is sent when a file is being added rather than just a fileName.

I have this setting in the DropzoneJs configuration:

removedfile: function(file) {
         $.ajax({
           type: 'POST',
           url: '/file-delete/',
           data: {fileToDelete: file, action: 'delete'},
           sucess: function(data){
              console.log(data);
           }
         });
         var _ref;
          return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
       },

The problem is that it returns this jQuery error:

'Uncaught TypeError: Illegal invocation' at ajax request

The file variable is apparently not in the format that can be sent as an normal file type format (from an input type=file).

Do you have any idea how to transfer the file variable so it can be sent as any other uploaded file?

According to the documentation, the file variable should be the type as it is described here: https://developer.mozilla.org/en-US/docs/Web/API/File

But still I didn't find the right solution.

Thank you.


EDIT: I added these to lines in the ajax configuration and now it doesn't throw an error but sends request without the data (fileToDelete and action). At least it seems so, I use Symfony and the request part is empty..

contentType: false,
processData: false,

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...