AWS IOS SDK (AWSS3TransferUtility)
v2.6.27
Both
No
Tested only on 11.4.1
CocoaPods
let fileLocation = URL(fileURLWithPath: filePath)
let transferUtility = AWSS3TransferUtility.default()
let multiPartExpression = AWSS3TransferUtilityMultiPartUploadExpression()
multiPartExpression.progressBlock = { task, curProgress in
let pval = Int(curProgress.fractionCompleted * 100)
print("multipart progress = \(pval)")
}
var multiPartCompletion: AWSS3TransferUtilityMultiPartUploadCompletionHandlerBlock?
multiPartCompletion = { task, error in
print("completed multi part upload")
if let err = error {
print("multipart error = \(err)")
}
}
transferUtility.uploadUsingMultiPart(
fileURL: fileLocation,
bucket: "bucket",
key: uploadKey,
contentType: "video/mp4",
expression: multiPartExpression,
completionHandler: multiPartCompletion).continueWith { task -> Any? in
if let res = task.result {
print("multipart task result = \(res)")
}
if let err = task.error {
print("multipart task error = \(err)")
}
return nil
}
After this code runs I keep getting a Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=4 "(null)" error from the AWSTask.
If you need help with understanding how to implement something in particular then we suggest that you first look into our developer guide. You can also simplify your process of creating an application by using Mobile Hub.
@sfisherjr
An error code of 4 maps to AWSS3TransferUtilityErrorLocalFileNotFound. Can you double check the value for fileLocation to see if has been set correctly to the file that you are trying to upload
Awesome, thanks for the help.
Looks like URL.absoluteString and passing that then converting to URL was the cause.
@sfisherjr What was the fix finally?
I'm currently getting this error. What was the fix? I think there is something weird when getting a video's MediaURL (which is NSURL) and then trying to use transferUtility.uploadUsingMultiPartFile() which takes a URL?
I did some more digging, and i think the technique of retrieving a video from the camera roll doesn't provide the right URL. When a video on the camera roll is selected, its compressed or trimmed.
The resulting URL is something like this:
file:///private/var/mobile/Containers/Data/PluginKitPlugin/9AB76B2D-E2BA-4570-9DBA-BE945E3935D5/tmp/trim.817B3892-C5B1-42E5-8035-3472CF631885.MOV
This fails to be uploaded with a "file not found" error.
If i do the same technique with an image, the URL is something like this:
file:///private/var/mobile/Containers/Data/Application/3BABCD38-87F1-40F8-8062-FC6AD544B250/tmp/D7C5740D-FEEC-4E7A-B040-A5D7D440C4C4.jpeg
Notice the difference in where the file lives. I think the app or the transferutility can't get files from "PluginKitPlugin".
I believe the issue was that I was storing the URL as absoluteString. Then when requesting, it would convert it to a URL and it was giving me some weird location.
I figured this out. It is a difference in iOS13. Previous versions did not have this issue.
In iOS13 selected videos from the imagePickerController get returned to a temp file in the "PluginKitPlugin" folder. This is only accessible by your app very temporarily.
What you have to do while the mediaURL for the video is available, copy it to your local Apps' temp directory. You will be able to upload and manipulate it as you wish. After you are done, you can delete it from the app's temporary directory.
You will no longer get the the "file not found" error (Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=4) from the TransferUtility.
This was key to me figuring this out.
A video selected will have the below mediaURL. Notice the "PluginKitPlugin" folder.
file:///private/var/mobile/Containers/Data/PluginKitPlugin/9AB76B2D-E2BA-4570-9DBA-BE945E3935D5/tmp/trim.817B3892-C5B1-42E5-8035-3472CF631885.MOV
An image selected will have the below imageURL. The GUID in the Application folder represents your own app. So you should have access to any data in there. Notice there is also a tmp directory.
file:///private/var/mobile/Containers/Data/Application/3BABCD38-87F1-40F8-8062-FC6AD544B250/tmp/D7C5740D-FEEC-4E7A-B040-A5D7D440C4C4.jpeg
Good to know! I wasn鈥檛 using the image picker, had a custom camera solution at that time. I鈥檇 imagine iOS will take care of the temp folder too automatically which would make it so much easier to work with large video and image files.
Most helpful comment
I figured this out. It is a difference in iOS13. Previous versions did not have this issue.
In iOS13 selected videos from the imagePickerController get returned to a temp file in the "PluginKitPlugin" folder. This is only accessible by your app very temporarily.
What you have to do while the mediaURL for the video is available, copy it to your local Apps' temp directory. You will be able to upload and manipulate it as you wish. After you are done, you can delete it from the app's temporary directory.
You will no longer get the the "file not found" error (Error Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=4) from the TransferUtility.
This was key to me figuring this out.
A video selected will have the below mediaURL. Notice the "PluginKitPlugin" folder.
file:///private/var/mobile/Containers/Data/PluginKitPlugin/9AB76B2D-E2BA-4570-9DBA-BE945E3935D5/tmp/trim.817B3892-C5B1-42E5-8035-3472CF631885.MOV
An image selected will have the below imageURL. The GUID in the Application folder represents your own app. So you should have access to any data in there. Notice there is also a tmp directory.
file:///private/var/mobile/Containers/Data/Application/3BABCD38-87F1-40F8-8062-FC6AD544B250/tmp/D7C5740D-FEEC-4E7A-B040-A5D7D440C4C4.jpeg