简体   繁体   English

使用 vue-wysiwyg 上传图片的问题

[英]Issues in image uploading using vue-wysiwyg

I am using vue-wysiwyg editor in my laravel-vue application.我在 laravel-vue 应用程序中使用vue- wysiwyg编辑器 In this editor there is an option to upload images and through incomplete documentation of this package I am able to upload the image and get public url of the uploaded file.在这个编辑器中有一个上传图片的选项,通过这个包的不完整文档,我可以上传图片并获取上传文件的公共网址。 But this package works sometimes and does not work at all sometimes.但是这个包有时有效,有时根本不起作用。

Here is how I am using this package这是我如何使用这个包

main.js主文件

import wysiwyg from "vue-wysiwyg";

Vue.use(wysiwyg, {
    forcePlainTextOnPaste: true,
    image: {
        uploadURL: "/api/save-support-files",
        dropzoneOptions: {}
    },
});

/api/save-support-files /api/save-support-files

public function uploadUserFile(Request $request)
    {
        $uploadedFile = $request->file('file');


        if (false == $uploadedFile) {
            return response()->api(false, 'Kindly upload a file');
        }

        $allowed_file_extentions = [
            'jpeg',
            'png',
            'jpg',
            'gif',
            'svg'
        ];

        if (false == in_array($uploadedFile->getClientOriginalExtension(), $allowed_file_extentions)) {
            return response()->api(false,'Allowed file types are jpeg, png, jpg, gif, svg',null);
        }


        $file_url = Storage::disk('public')->putFileAs('/support-files',$uploadedFile,generateRandomString('5').'.'.$uploadedFile->getClientOriginalExtension());

//        return response()->api(true,'File uploaded successfully',config('app.url').'/storage/'.$file_url);

        return config('app.url').'/storage/'.$file_url;
}

Issues I am facing right now:我现在面临的问题:

  1. As soon as I select image from file browser, image is uploaded through api successfully but it is not showing in editor.一旦我从文件浏览器中选择图像,图像就会通过 api 成功上传,但它没有显示在编辑器中。

  2. Unable to select already uploaded image, I have to refresh the page and then again select file to upload it again.无法选择已上传的图片,我必须刷新页面,然后再次选择文件以再次上传。

Is anyone having solution to this problem ?有没有人解决这个问题? Kindly help me out.请帮帮我。

my upload store function look like this:我的上传存储功能如下所示:

public function store(Request $request)
{
    $request->validate(['file' => 'required']);

    $file = $request->file('file');
    if ($file->isValid()) {
        $path = $file->storePublicly(now()->format('Y' . DIRECTORY_SEPARATOR . 'm' . DIRECTORY_SEPARATOR . 'd'));

        return response(Storage::disk('public')->url($path), Response::HTTP_CREATED)->withHeaders(
            [
                'content-type' => 'text/html'
            ]
        );
    }

    abort(Response::HTTP_BAD_REQUEST);
}

make sure you have set APP_URL in .env to full url ( http://my-site.com )确保您已将APP_URL中的.env设置为完整 url ( http://my-site.com )

make sure you run php artisan storage:link确保您运行php artisan storage:link

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM