ios - 无法上传图片(React Native,Laravel)
问题描述
我已经尝试了一段时间但没有成功
后端
public function createInspection(Request $request) {
$path = Storage::disk('public')->putFile('bin_images', new File($request->file('image')));
return $path;
}
客户
data.append("image", {
uri: this.state.images[0].path,
type: this.state.images[0].mime,
size: this.state.images[0].size,
name: filename
});
this.props.sendInspection(data)
服务(缩短)
const res = await axios.post(url, data, {
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
"Content-Type": "multipart/form-data"
}
});
我不确定这是否与无法识别路径(ios图像路径)有关,例如路径:
/private/var/mobile/Containers/Data/Application/B6FEB0FD-F9C8-4088-B15F-99D27A818C76/tmp/react-native-image-crop-picker/7BD81594-30E0-4E00-919C-4F353BBDE46F.jpg
我收到这个错误
message: "The file "" does not exist", exception: "Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException", file: "/Users/ysr/tza-project/vendor/symfony/http-foundation/File/File.php", line: 37, file: "/Users/ysr/tza-project/vendor/symfony/http-foundation/File/MimeType/MimeTypeGuesser.php", line: 116
解决方案
问题似乎出在您的后端,请查看文档。
你应该这样做:
public function update(Request $request)
{
$path = $request->file('image')->store('images');
return $path;
}
如果您想使用putFile
,则可以使用:
$path = Storage::putFile('images', $request->file('image'));
如果需要更换磁盘,则:
$path = Storage::disk('public')->putFile('images', $request->file('image'));
推荐阅读
- xamarin.android - 在应用链接冷启动时显示启动画面
- python - 为给定尺寸创建包含裁剪图像的新图像
- azure-functions - Azure Function Service Bus 触发器的触发次数多于队列中的消息
- ios - Swift Class 有另一个来自 Pod 的带有 UiViewController 的类,因此在插座上获得 Nil
- java - @Valid 不适用于嵌套对象(Java / Spring Boot)
- java - Java 服务器上下文和 JNDI 缺少条目
- database - pgAdmin 4 - 查询工具自动完成的性能非常差,这正常吗?
- c++ - 无法打破c ++中的无限循环
- php - .htaccess 链接重写返回 404 错误
- javascript - 为什么这不在屏幕上渲染地图?我正在使用 D3 库,我的 geojson 文件工作正常