简体   繁体   English

如何在 laravel 中上传和存储 3d 图像

[英]how to upload and store 3d images in laravel

I am using input file type我正在使用输入文件类型

<input type="file" name="file-3D" id="file-3D>

And here is the code in my controller, where I have a variable $product with model Product and I have column name called threeD_img这是我的 controller 中的代码,其中我有一个带有 model Product 的变量 $product ,我有一个名为 threeD_img 的列名

        if ($request->hasFile('file-3D')) {


          $threeD_image = $request->file('file-3D');
  
          $hashedname   = $threeD_image->hashName();


          $threeD_image->storeAs('public/product/', $hashedname   );

          $product->threeD_img =$hashedname;
        
    }

However, when I upload the file and store the 3d images with extension.gltf, I either get null value or.json file with some objects.但是,当我上传文件并存储带有扩展名.gltf 的 3d 图像时,我会得到 null 值或带有一些对象的 json 文件。

How would I upload and store 3d objects into my file system?如何将 3d 对象上传并存储到我的文件系统中?

I already tested the code with jpg, png images and it works fine.我已经用 jpg、png 图像测试了代码,它工作正常。

I just found out that you just need to change the way you upload file:我刚刚发现您只需要更改上传文件的方式:

Storage::disk('public')->put('assets/' . $request->file3d->getClientOriginalName(), $request->file3d->get());

The code above will let you upload/save any kind of file to your server, and will avoid converting it to any weird kind of file such as .bin , .json or null.上面的代码将允许您将任何类型的文件上传/保存到您的服务器,并将避免将其转换为任何奇怪的文件类型,例如.bin.json或 null。

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

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