Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can not upload file to local server with this demo #1

Open
lijian860428 opened this issue Sep 26, 2021 · 0 comments
Open

I can not upload file to local server with this demo #1

lijian860428 opened this issue Sep 26, 2021 · 0 comments

Comments

@lijian860428
Copy link

NSString *accessKey = @"admin";
NSString *secretKey = @"admin123456";

    //[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:9000", [SPUserInstance sharedInstance].userPrivateIp]]
    AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:accessKey secretKey:secretKey];
    AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
                                                                              endpoint:[[AWSEndpoint alloc] initWithRegion:AWSRegionUSEast1 service:AWSServiceS3 URL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:9000", [SPUserInstance sharedInstance].userPrivateIp]]] credentialsProvider:credentialsProvider];
    [AWSS3 registerS3WithConfiguration:configuration forKey:@"test"];
    _awss3Client = [AWSS3 S3ForKey:@"test"];

unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:fileUrlString error:nil] fileSize];

AWSS3PutObjectRequest *request = [[AWSS3PutObjectRequest alloc] init];
request.bucket = kBucketName;
request.key = objectKey;
request.body = [NSURL fileURLWithPath:fileUrlString];

request.contentLength = @(fileSize);

request.uploadProgress = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"11111111111 sent = %lld, totalsent = %lld, expecteTotalSent = %lld", bytesSent, totalBytesSent, totalBytesExpectedToSend);

    progressBlock(bytesSent, totalBytesSent, totalBytesExpectedToSend);
};

[[self.awss3Client putObject:request] continueWithBlock:^id _Nullable(AWSTask<AWSS3PutObjectOutput *> * _Nonnull task) {
    if (task.error) {
        failedBlock([NSString stringWithFormat:@"%ld", task.error.code], task.error.localizedDescription);
    } else {
        successBlock(objectKey);
    }

    return nil;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant