From ab3be84b9b1b4d81680c6d2cf426190ba2a06cfb Mon Sep 17 00:00:00 2001 From: Vasile Date: Fri, 23 Jun 2023 12:09:07 +0300 Subject: [PATCH] fix(ios): iosGetImageDataById for videos (#500) * Fix get video data with iosGetImageDataById * Update README.md with uploading example --- README.md | 15 +++++++++++++++ ios/RNCCameraRoll.mm | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4018a61..e41f2dc 100644 --- a/README.md +++ b/README.md @@ -480,6 +480,21 @@ CameraRoll.iosGetImageDataById(internalID, true); | internalID | string | Yes | Ios internal ID 'PH://xxxx'. | | convertHeic | boolean | False | Whether to convert or not to JPEG image. | +Upload photo/video with `iosGetImageDataById` method + +```javascript + +try { +// uri 'PH://xxxx' +const fileData = await CameraRoll.iosGetImageDataById(uri); +if (!fileData?.node?.image?.filepath) return undefined; +const uploadPath = imageData.node.image.filepath; // output should be file://... +// fetch or ReactNativeBlobUtil.fetch to upload +} +catch (error) {} + +``` + ### `useCameraRoll()` diff --git a/ios/RNCCameraRoll.mm b/ios/RNCCameraRoll.mm index 5124bac..e25c07c 100644 --- a/ios/RNCCameraRoll.mm +++ b/ios/RNCCameraRoll.mm @@ -629,7 +629,13 @@ RCT_EXPORT_METHOD(getPhotoByInternalID:(NSString *)internalId editOptions.networkAccessAllowed = YES; [asset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { - imageURL = contentEditingInput.fullSizeImageURL; + if (contentEditingInput.mediaType == PHAssetMediaTypeImage) { + imageURL = contentEditingInput.fullSizeImageURL; + } else { + AVURLAsset *avURLAsset = (AVURLAsset*)contentEditingInput.audiovisualAsset; + imageURL = [avURLAsset URL]; + } + if (imageURL.absoluteString.length != 0) { filePath = [imageURL.absoluteString stringByReplacingOccurrencesOfString:@"pathfile:" withString:@"file:"];