我正在使用下面的libs3库进行文件上传:http://libs3.ischo.com/dox/index.html

我虽然回来了错误S3StatusConnectionFailed。有人可以指出我这种情况如何发生吗?这是我将文件上传到S3的功能。

int putFileIntoS3 (char *fileName, char *s3ObjName) {

S3Status status;
char *key;
struct stat statBuf;
uint64_t fileSize;
FILE *fd;
char *accessKeyId;
char *secretAccessKey;
put_object_callback_data data;

accessKeyId = S3_ACCESS_KEY;
secretAccessKey = S3_SECRET_ACCESS_KEY;


key = (char*) strchr(s3ObjName, '/');
if (key == NULL) {
    printf("S3 Key not defined!!!!");
    return (-1);
}


*key = '\0';
key++;
if (stat(fileName, &statBuf) == -1) {
    printf("Unknown input file");
    return(-1);
}

fileSize = statBuf.st_size;

fd = fopen(fileName, "r");
if (fd == NULL) {
    printf("Unable to open input file");
    return(-1);
}

data.infile = fd;

S3BucketContext bucketContext =
    {s3ObjName, S3ProtocolHTTP, S3UriStylePath, accessKeyId, secretAccessKey}

S3PutObjectHandler putObjectHandler = {
    { &responsePropertiesCallback, &responseCompleteCallback },
    &putObjectDataCallback
};

if ((status = S3_initialize("s3", S3_INIT_ALL)) != S3StatusOK) {
    printf("Failed to initialize libs3: %s\n",S3_get_status_name(status));
    return(-1);
}

S3_put_object(&bucketContext, key, fileSize, NULL, 0, &putObjectHandler, &data);

if (statusG != S3StatusOK) {
    printf("Put failed: %i\n", statusG);
    S3_deinitialize();
    return(-1);
}

S3_deinitialize();

fclose(fd);
return(0);

}


我回来了“放置失败:46”,我敢肯定,这是一个S3StatusConnectionFailed错误。

任何帮助都将是巨大的,甚至指向我可以使用的类似于boto的库的指针,而不是用C ++编写的繁琐工作。

谢谢!

最佳答案

好吧,我尝试将非空值,但我得到相同的错误。我发现了这个原因:您必须按如下所示设置“数据”(类型为put_object_callback_data)的contentLength

fileSize = statBuf.st_size;
//viren+
data.contentLength = fileSize;
//viren-
//..
data.infile = fd;


哦,还要确保您对存储桶设置了正确的权限。

关于c - libs3 S3StatusConnectionFailed,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6794327/

10-12 13:48