Reputation: 450
I want to upload a picture to my Google Cloud Storage Bucket from my ios Application. I am using a http post method to add the picture. However, I want to know the exact URI to use in my code for a http Post method because Google Documentation uses so many and is unclear to the exactness. If the name of my bucket is test1212test what is the exact URI?
Upvotes: 1
Views: 862
Reputation: 450
That is not what I was looking for. That is what is in the Google Documentation however it did not work because my objective was to upload a picture straight from my phone to the google bucket. So instead, in my python API I returned a uploadURL generated by the blobstore and sent it to my iOS app and used that exact upload url and it worked.
In Python API:
USER_BUCKET = '%s-%d-%s-%d' % (first, age, email, now)
my_upload_url = blobstore.create_upload_url('/upload',
gs_bucket_name=USER_BUCKET)
I made then a unique bucket name, then I created their unique upload URL.
In iOS app:
NSString *uploadUrl = [[NSUserDefaults standardUserDefaults] stringForKey:@"uploadUrl"];
//This is your version
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:uploadUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSData* imageData = UIImagePNGRepresentation(_image);
[formData appendPartWithFileData:imageData name:@"file" fileName:@"testImages" mimeType:@"image/jpeg"];
} progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"Response: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
The uploadUrl is what was created in Python and I just saved it to the users NSUsersDefaults.
Upvotes: 1
Reputation: 5511
See Request URIs - any of the following should work:
test1212test.storage.googleapis.com
storage.googleapis.com/test1212test
storage-upload.googleapis.com/test1212test
test1212test.storage-upload.googleapis.com
Upvotes: 1