用针将画布发送到laravel服务器

时间:2020-03-17 02:16:00

标签: javascript laravel ecmascript-6 electron

我正在尝试使用针杆将画布发送到Laravel服务器。我现在有以下解决方法。

我要发送此邮件:

数据:图像/ JPEG; BASE64,/ 9J / 4AAQSkZJRgABAQAAAQABAAD / 2wBDABIMDRANCxIQDhAUExIVGywdGxgYGzYnKSAsQDlEQz85Pj1HUGZXR0thTT0 + WXlaYWltcnNyRVV9hnxvhWZwcm7 / 2wBDARMUFBsXGzQdHTRuST5Jbm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm7 / wAARCAJYAyADASIAAhEBAxEB / 8QAFQABAQAAAAAAAAAAAAAAAAAAAAb / xAAUEAEAAAAAAAAAAAAAAAAA

这是我的脚本:

exports.screenShotURL = (image, tracker_id, user_id) => {
    log.info(tracker_id);
    log.info(user_id);
    log.info(image);

    postData = {};
    postData.file = image;

    var options = {
        headers: { accept: 'multipart/form-data', authorization: 'Bearer ' + access_token },
        data: postData
    };

    needle.post('http://localhost:8000/api/my-time-tracker/' + user_id + '/screenshot/' + tracker_id, options, function(
    err,
    resp
) {
    log.info(resp);
});

};

在laravel中:

    public function saveFileUpload(Request $request, $folderPath, $desc, $ispublic=true, $recordId=0){

    $uploadFiles = $request->file();
    $uploadFile = null;
    $filename = null;
    $filesize = 0;
    $attachmentId = 0;
    if($uploadFiles){
        $uploadFile = $uploadFiles[0];
        $filesize = $uploadFile->getClientSize();
        $filename = time(). '-' . $uploadFile->getClientOriginalName();
        //$uploadFile = $uploadFile->move(public_path().$folderPath, $filename);
        if($ispublic){
            $storagePath = Storage::put($folderPath, $uploadFile, 'public');
        }else{
            $storagePath = Storage::put($folderPath, $uploadFile);
        } 

        if($recordId > 0){
            $attachmentData = Attachment::find($recordId);
            $attachmentData->modified_by = Auth::user()->id;
        }else{
            $attachmentData = new Attachment();
            $attachmentData->created_by = Auth::user()->id;
        }

        $attachmentData->att_filename = $filename;
        $attachmentData->att_filesize = $filesize;
        $attachmentData->att_description = $desc;
        $attachmentData->att_storage_path = $storagePath;
        $attachmentData->save();

        $attachmentId = $attachmentData->id;
    }

    return $attachmentId;

}

我相信标题格式存在问题,因为我能够成功连接邮递员。

enter image description here

0 个答案:

没有答案