Upload file to amazon s3 by lens c

I am using below code to upload File.doc file to amazon s3 server.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"File" ofType:@"doc"];
    AFAmazonS3Manager *s3Manager = [[AFAmazonS3Manager alloc] initWithAccessKeyID:@"*********" secret:@"***********"];
        s3Manager.requestSerializer.region = AFAmazonS3USStandardRegion;
        s3Manager.requestSerializer.bucket = @"**********";
        [s3Manager getBucket:s3Manager.requestSerializer.bucket success:^(id responseObject) {
            NSLog(@"Upload Complete: ");

        }
                     failure:^(NSError *error) {
                         NSLog(@"Error: %@", error);
                     }];

        [s3Manager postObjectWithFile:@"/File.doc"
                      destinationPath:filePath
                           parameters:nil
                             progress:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                                 NSLog(@"%f%% Uploaded", (totalBytesWritten / (totalBytesExpectedToWrite * 1.0f) * 100));
                             }
                              success:^(id responseObject) {
                                  NSLog(@"Upload Complete: ");
                             }
                              failure:^(NSError *error) {
                                  NSLog(@"Error: %@", error);
                              }];

      

But this always gives me below error. I cannot find how to fix this problem. Please, help: -

Error: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo=0x6080000e6000 {NSUnderlyingError=0x600000055c60 "The requested URL was not found on this server.", NSErrorFailingURLStringKey=file:///File.doc, NSErrorFailingURLKey=file:///File.doc, NSLocalizedDescription=The requested URL was not found on this server.}
2015-07-04 10:12:45.181 AmazonS3foriOSinOSX[681:18782] Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo=0x6080000e6c00 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x60800003fd20> { URL: https://ttdrivemacsync.s3.amazonaws.com/ttdrivemacsync } { status code: 403, headers {
    "Content-Type" = "application/xml";
    Date = "Sat, 04 Jul 2015 04:41:38 GMT";
    Server = AmazonS3;
    "Transfer-Encoding" = Identity;
    "x-amz-id-2" = "l8twK33h6BPEeVmUPEKNSHBqAlJMsyQhLeGm8ARJUeQtFHiMjV+lmIqKmAnW6xl4QMO2P7weiwk=";
    "x-amz-request-id" = FC8CD3722495097D;
} }, NSErrorFailingURLKey=https://ttdrivemacsync.s3.amazonaws.com/ttdrivemacsync, com.alamofire.serialization.response.error.data=<3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 4572726f 723e3c43 6f64653e 5369676e 61747572 65446f65 734e6f74 4d617463 683c2f43 6f64653e 3c4d6573 73616765 3e546865 20726571 75657374 20736967 6e617475 72652077 65206361 6c63756c 61746564 20646f65 73206e6f 74206d61 74636820 74686520 7369676e 61747572 6520796f 75207072 6f766964 65642e20 43686563 6b20796f 7572206b 65792061 6e642073 69676e69 6e67206d 6574686f 642e3c2f 4d657373 6167653e 3c415753 41636365 73734b65 7949643e 414b4941 4a444842 5948434f 3553414c 46563351 3c2f4157 53416363 6573734b 65794964 3e3c5374 72696e67 546f5369 676e3e47 45540a0a 0a536174 2c203034 204a756c 20323031 35203034 3a34323a 34312047 4d540a2f 74746472 6976656d 61637379 6e632f74 74647269 76656d61 6373796e 633c2f53 7472696e 67546f53 69676e3e 3c536967 6e617475 72655072 6f766964 65643e6c 53436d51 36436d42 44644f4a 73356f65 6f4d4d59 4d725666 46453d3c 2f536967 6e617475 72655072 6f766964 65643e3c 53747269 6e67546f 5369676e 42797465 733e3437 20343520 35342030 61203061 20306120 35332036 31203734 20326320 32302033 30203334 20323020 34612037 35203663 20323020 33322033 30203331 20333520 32302033 30203334 20336120 33342033 32203361 20333420 33312032 30203437 20346420 35342030 61203266 20373420 37342036 34203732 20363920 37362036 35203664 20363120 36332037 33203739 20366520 36332032 66203734 20373420 36342037 32203639 20373620 36352036 64203631 20363320 37332037 39203665 2036333c 2f537472 696e6754 6f536967 6e427974 65733e3c 52657175 65737449 643e4643 38434433 37323234 39353039 37443c2f 52657175 65737449 643e3c48 6f737449 643e6c38 74774b33 33683642 50456556 6d555045 4b4e5348 4271416c 4a4d7379 51684c65 476d3841 524a5565 51744648 694d6a56 2b6c6d49 714b6d41 6e573678 6c34514d 4f325037 77656977 6b3d3c2f 486f7374 49643e3c 2f457272 6f723e>, NSLocalizedDescription=Request failed: forbidden (403)}

      

SEPARATE ANSWER I edited the path. But still it shows me the error.

[s3Manager postObjectWithFile:filePath
              destinationPath:@"/File.doc"
                   parameters:nil
                     progress:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
                         NSLog(@"%f%% Uploaded", (totalBytesWritten / (totalBytesExpectedToWrite * 1.0f) * 100));
                     }
                      success:^(id responseObject) {
                          NSLog(@"Upload Complete: ");

                      }

                      failure:^(NSError *error) {
                          NSLog(@"Error: %@", error);
                      }];

      

Now it shows me below error: -

2015-07-05 15:19:37.269 AmazonS3foriOSinOSX[1042:15280] Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo=0x6080000e8e80 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x60000003f520> { URL: https://ttdrivemacsync.s3.amazonaws.com/ttdrivemacsync } { status code: 404, headers {
    "Content-Type" = "application/xml";
    Date = "Sun, 05 Jul 2015 09:48:36 GMT";
    Server = AmazonS3;
    "Transfer-Encoding" = Identity;
    "x-amz-id-2" = "yTieaDnXk11GHxwJVWxOYJq7Q4KgZ+1zp1Uw7HIcQBuOwgJwHnuWiqdDKqiEJlTMJWgWA1zENW4=";
    "x-amz-request-id" = 2C1200DD79968B33;
} }, NSErrorFailingURLKey=https://ttdrivemacsync.s3.amazonaws.com/ttdrivemacsync, com.alamofire.serialization.response.error.data=<3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 4572726f 723e3c43 6f64653e 4e6f5375 63684b65 793c2f43 6f64653e 3c4d6573 73616765 3e546865 20737065 63696669 6564206b 65792064 6f657320 6e6f7420 65786973 742e3c2f 4d657373 6167653e 3c4b6579 3e747464 72697665 6d616373 796e633c 2f4b6579 3e3c5265 71756573 7449643e 32433132 30304444 37393936 38423333 3c2f5265 71756573 7449643e 3c486f73 7449643e 79546965 61446e58 6b313147 4878774a 5657784f 594a7137 51344b67 5a2b317a 70315577 37484963 5142754f 77674a77 486e7557 69716444 4b716945 4a6c544d 4a576757 41317a45 4e57343d 3c2f486f 73744964 3e3c2f45 72726f72 3e>, NSLocalizedDescription=Request failed: not found (404)}
2015-07-05 15:19:38.117 AmazonS3foriOSinOSX[1042:15280] 100.000000% Uploaded
2015-07-05 15:19:40.636 AmazonS3foriOSinOSX[1042:15280] Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: method not allowed (405)" UserInfo=0x6080000e9a00 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x600000035400> { URL: https://ttdrivemacsync.s3.amazonaws.com/File.doc } { status code: 405, headers {
    Allow = "GET, DELETE, HEAD, PUT";
    Connection = close;
    "Content-Type" = "application/xml";
    Date = "Sun, 05 Jul 2015 09:48:37 GMT";
    Server = AmazonS3;
    "Transfer-Encoding" = Identity;
    "x-amz-id-2" = "toytUIQkaJzakm4tSkkSWew7gZUrql+hAMfGdYBc759z8VDORtaxEqtfMRNTqnZ7aVJwxns7074=";
    "x-amz-request-id" = 2007EC30B9F13D9E;
} }, NSErrorFailingURLKey=https://ttdrivemacsync.s3.amazonaws.com/File.doc, com.alamofire.serialization.response.error.data=<3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 4572726f 723e3c43 6f64653e 4d657468 6f644e6f 74416c6c 6f776564 3c2f436f 64653e3c 4d657373 6167653e 54686520 73706563 69666965 64206d65 74686f64 20697320 6e6f7420 616c6c6f 77656420 61676169 6e737420 74686973 20726573 6f757263 652e3c2f 4d657373 6167653e 3c4d6574 686f643e 504f5354 3c2f4d65 74686f64 3e3c5265 736f7572 63655479 70653e4f 424a4543 543c2f52 65736f75 72636554 7970653e 3c526571 75657374 49643e32 30303745 43333042 39463133 4439453c 2f526571 75657374 49643e3c 486f7374 49643e74 6f797455 49516b61 4a7a616b 6d347453 6b6b5357 65773767 5a557271 6c2b6841 4d664764 59426337 35397a38 56444f52 74617845 7174664d 524e5471 6e5a3761 564a7778 6e733730 37343d3c 2f486f73 7449643e 3c2f4572 726f723e>, NSLocalizedDescription=Request failed: method not allowed (405)}

      

+3


source to share


2 answers


Take a look here: Submit Amazon S3 Request with AFNetworking



The final problem is solved by changing postObjectWithFile to putObjectWithFile.

+3


source


You have confused the file path and destination path,



he should be postObjectWithFile:filePath destinationPath:@"/File.doc"

+1


source







All Articles