Upload File & Data Problem
I'm using FilePond & it passes the file to you in a function. I'm trying to do a simple file upload w/ additional upload data. Here's my js:
- function fpUpload(fieldName, file, metadata, load, error, progress, abort) {
- console.log('InsideFP-Upload: ' , upload); // set further up
- console.log('InsideFP-File: ' , file);
- var obj_data = {};
- obj_data['upload'] = upload;
- obj_data['myfile'] = file;
- var imgData = new FormData();
- $.each(obj_data, function(k, v) {
- console.log(['Key, Value & myfilecheck: ', k, v, k == 'myfile']);
- if (k == 'myfile') {$.each(v, function(i, file) {imgData.append(k, file)})}
- else {imgData.append(k, v)}
- });
- $.ajax({
- url: 'path/uploadimg.php', // get img url
- data: imgData,
- dataType : 'json',
- contentType: false,
- processData: false,
- type: 'POST'
- })
- .done(function(data) {
- if (data.success == true) {
- // Call the progress method to update the progress to 100% before calling load
- // Setting computable to false switches the loading indicator to infinite mode
- // (computable, processedSize, totalSize)
- progress(true, 0, 1024);
- // Call the load method when done and pass the returned server file id
- // the load method accepts either a string (id) or an object
- // the unique server file id is used by revert and restore functions
- load('unique-file-id');
- }
- })
- .fail(function(data) {
- if (data.success == false) {
- console.log('ImgFailMessage: ' + data.message);
- // Call the error method if something is wrong, should exit after
- error('Error occurred');
- }
- });
- // Abort method so the request can be cancelled by user
- return {
- abort: function() {
- // User tapped abort, cancel ongoing actions here
- // Let FilePond know the request has been cancelled
- abort();
- }
- };
- }
Here's the console output - I think it looks ok at this point?