ushaprasanna.t's avatar

Laravel 5.4 ajax formdata request returns empty array while uploading a file over https

Hi All,

I am a new bie.. I am facing this issue for the past 1 day.

Right now am working for a chatting application where logged user can send images/documents through the chat. The connection is secured that is it runs on HTTPS. I have the below JS code which sends the attached files in Formdata,

            fileChunk = new FormData();
            fileChunk.append('Slice', uploader.fileToBeUploaded.slice(start, end));

            var param = JSON.parse(localStorage["meta_data"]);
            fileChunk.append('NewFileName', encodeURI(param.NewFileName));


            jqxhr = $.ajax({
                async: true,
                url: (letchatajax_path + 'UploadChunk?id=' + uploader.currentChunk + "&start=" + start),
                data: (fileChunk),//JSON.stringify
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST'
            }).fail(function (request, error) {
                if (error !== 'abort' && retryCount < uploader.maxRetries) {
                    ++retryCount;
                    setTimeout(sendNextChunk, uploader.retryAfterSeconds * 1000);
                }
                if (error === 'abort') {
                    //displayStatusMessage(cful, "Aborted");
                }
                else {
                    if (retryCount === uploader.maxRetries) {
                        //displayStatusMessage(cful, "Upload timed out.");
                        //resetControls();
                        uploader = null;
                    }
                    else {
                        //displayStatusMessage(cful, "Resuming Upload");
                    }
                }
                return;
            }).done(function (state) {
                if (state.error || state.isLastBlock) {
                    //cful.displayStatusMessage(cful, state.message);
                    return;
                }
                ++cful.currentChunk;
                start = (cful.currentChunk - 1) * cful.blockLength;
                end = Math.min(cful.currentChunk * cful.blockLength, cful.fileToBeUploaded.size);
                retryCount = 0;
                cful.updateProgress(cful);
            });

We use Laravel 5.4 and route in the web.php is set as below, Route::post('/UploadChunk','UWebController@UploadChunk');

The method definition in the Controller is as below,

function UploadChunk(Request $request){
    $requestparams = $request->all();

        $model = new UploadFileData();
        $model->FileName    = $requestparams['NewFileName'];


            $FolderName = public_path().'/uatstorageservice/CHAT_FILES/';
    $request->file('Slice')->move($FolderName,  $model->FileName);
}

Now at this stage its throwing the error below,

FatalThrowableError in UWebController.php line 348: to a member function move() on null

Please help..

0 likes
0 replies

Please or to participate in this conversation.