通过https上传文件时,不会出现Laravel 5.4 ajax formdata请求

时间:2017-08-08 11:35:07

标签: jquery ajax laravel-5.4

现在正在为聊天应用程序工作,其中记录的用户可以通过聊天发送图像/文档。连接是安全的,它在HTTPS上运行。我有以下JS代码,它发送附加文件在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);
        });

我们使用Laravel 5.4和web中的路由.php设置如下,Route::post('/UploadChunk','UWebController@UploadChunk');

控制器中的方法定义如下:

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);
}

现在在这个阶段,当我尝试读取与“图像”数据相关的请求变量“Slice”时,它会抛出下面的错误,

  

UWebController.php第348行中的FatalThrowableError:对null的成员函数move()

请帮忙。

0 个答案:

没有答案