Oliver
Oliver

Reputation: 105

Simple TYPO3 Fluid fileupload with Ajax?

Currently I am stuck in finding a nice, compatible way to realize an Ajax-File-Upload in TYPO3 Fluid. I am aware of the Demo-Extension by Helmut Hummel on GitHub, but this is, as I see it, rather overkill for my needs and does not include "real" ajax submit. I absolutely DON`T want to have any page reload on that specific site. I want to build an ajax-upload of a csv-file, which gets analyzed by my own controller-action, the results shall be presented in a lightbox afterwards (confirmation step). Is there any elegant way to pass the text-contents of a file to my own controller in TYPO3?

Upvotes: 1

Views: 846

Answers (1)

Manthan Budheliya
Manthan Budheliya

Reputation: 91

You can simply send the file data as binary using jquery ajax or any other javascript framework from Front-end.

Here is the javascript/jQuery to send a file as binary.

var file_data = $("#upload").prop("files")[0];
var form_data = new FormData();
form_data.append('tx_extname_plugin[file]', file_data);
$.ajax({
  url: 'your action url',
  dataType: 'json',
  cache: false,
  contentType: false,
  processData: false,
  data: form_data,                         
  type: 'post',
  success: function(data){

  }
});

In Controller Action, you can upload the file from a controller as your desired position. After that, you can use the uploaded file for your further stuff.

public function demoAction(){
    $uploadedFile = $_FILE['file'];
}

May be this code is old school because I had implemented it year ago.

Upvotes: 2

Related Questions