上载到服务器后,React Native-react-native-camera(RNCamera)图像方向修复失败

时间:2019-05-27 03:17:03

标签: react-native react-native-camera

我曾经使用// some code here.... 'font_path' => base_path('resources/fonts/'), 'font_data' => [ "khmerosmoul" => [/* Khmer */ 'R' => "KhmerOSmuol.ttf", 'useOTL' => 0xFF, ], "khmerosmoullight" => [/* Khmer */ 'R' => "KhmerOSmuollight.ttf", 'useOTL' => 0xFF, ], "khmerosbokor" => [/* Khmer */ 'R' => "KhmerOSBokor.ttf", 'useOTL' => 0xFF, ], "khmerosmoulpali" => [/* Khmer */ 'R' => "KhmerOSmuolpali.ttf", 'useOTL' => 0xFF, 'useKashida' => 75 ] // ...add as many as you want. ] 水平拍摄照片(使用iPhone XS Max),然后应用RNCamera来修正错误的方向,代码在这里:

forceUpOrientation: true

然后我用takePicture = async () => { try { if (this.camera) { const options = { quality: 0.5, exif: true, forceUpOrientation: true }; const data = await this.camera.takePictureAsync(options); this.setState({ imgData: data }) } } catch (err) { console.log('err: ', err); } }; 上传图像,如下所示(代码的一部分):

RNFetchBlob

当我检查服务器中的图像时,水平图像会自动变为垂直图像。如果我使用Web API上传图像,并使用该图像通过画布旋转,则不会出现此类问题。

我也尝试过使用本地iPhone相机应用程序水平拍摄图像,这也没有问题。所以我想问题出在uploadPhotoAsFile: (user, uri, handleProgress) => async () => { const path = uri.replace("file://", ""); const formData = []; formData.push({ name: "file", filename: `photo.jpg`, data: RNFetchBlob.wrap(path) }); let response = await RNFetchBlob.fetch( "POST", `${API_BASE_URL}/members/${user.id}/photos`, { Accept: "application/json", "Content-Type": "multipart/form-data", client, 'access-token': token, 'token-type': tokenType, uid, }, formData ).uploadProgress({ interval : 50 }, (written, total) => { console.log('uploaded', written / total); handleProgress(Math.floor(100 * written / total)); }); . . .

我试图获取图像并获得图像方向RNCamera,它表明它仍然是垂直img(宽度<高度),这是代码:

Image.getSize()
this.getImgSize(sourceUri).then((resp) => {
   console.log(resp.width, resp.height)
})

为什么将img上传到服务器时定向修复不起作用?

0 个答案:

没有答案