Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

"403 forbidden" error when uploading selected file to S3 #116

Open
rtimpone opened this issue Dec 15, 2015 · 1 comment
Open

"403 forbidden" error when uploading selected file to S3 #116

rtimpone opened this issue Dec 15, 2015 · 1 comment

Comments

@rtimpone
Copy link

We're trying to use the iOS FilePicker SDK in a test app I'm putting together and I keep getting a 403 error when selecting a document.

The app is currently setup to do the following:

  1. Present an FPPickerController to the user
  2. User selects a source, then selects a file
  3. The selected file should be uploaded to our S3 bucket, then the S3 link should be returned to the FPPickerController's fpdelegate in an FPMediaInfo object

The selected file is successfully being uploaded to S3, but we're having two problems:

  1. If I specify a storePath (a directory inside of our default S3 bucket), it is being ignored and the file is instead uploaded to the root of the default S3 bucket. It looks like other users may be having this problem as mentioned in Doesn't save files to mentioned buckets and path #98.
  2. Once the file is successfully uploaded to our S3 bucket, an alert view appears with the text: "Request failed: forbidden (403)". This triggers the delegate method - (void)fpPickerControllerDidCancel:

Here is my app delegate code:

+ (void)initialize
{
    [FPConfig sharedInstance].APIKey = @"MY_API_KEY";
    [FPConfig sharedInstance].storeLocation = @"S3";
    [FPConfig sharedInstance].storeAccess = @"private";
    [FPConfig sharedInstance].storeContainer = @"my-bucket-name";
    [FPConfig sharedInstance].storePath = @"my-directory-name/";
}

And my ViewController code:

#pragma mark - Actions

- (IBAction)buttonAction: (id)sender
{
    FPPickerController *pickerController = [FPPickerController new];
    pickerController.fpdelegate = self;
    pickerController.dataTypes = @[ @"image/*" ];

    [self presentViewController: pickerController animated: YES completion: nil];
}

#pragma mark - FPPickerController Delegate Methods

- (void)fpPickerController: (FPPickerController *)pickerController didFinishPickingMediaWithInfo: (FPMediaInfo *)info
{
    NSLog(@"File Picker Controller Did Finish Picking Media With Info: %@", info);
}

- (void)fpPickerControllerDidCancel: (FPPickerController *)pickerController
{
    NSLog(@"File Picker Controller Did Cancel");
}

and the Podfile:

platform :ios, '8.0'

use_frameworks!

target :'MyAppName' do
  pod 'FPPicker', '~> 5.1.1'
end

Any help on this would be greatly appreciated. At this point, the two things I need are:

  1. A way to specify which directory in our S3 bucket the file should be saved to
  2. Access to the S3 link that the file was saved at
@pJes2
Copy link

pJes2 commented Jan 27, 2016

  1. Resolved with 5.1.4
  2. You can construct the link yourself - FPMediaInfo has property "key" and s3 link looks like this:
    "basic":
    https://BUCKET_NAME.s3.amazonaws.com/FPMEDIAINFO_KEY
    "advanced":
    https://s3-BUCKET_REGION.amazonaws.com/FPMEDIAINFO_KEY

both should work just fine, so you can use "basic" one to build your s3 link in
- (void)fpPickerController: (FPPickerController *)pickerController didFinishPickingMediaWithInfo: (FPMediaInfo *)info

It could look like this:

- (void)fpPickerController: (FPPickerController *)pickerController didFinishPickingMediaWithInfo: (FPMediaInfo *)info {
    NSString *s3URL = [NSString stringWithFormat:@"https://%@.s3.amazonaws.com/%@", [FPConfig sharedInstance].storeContainer, info.key];
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants