libs3 S3StatusConnectionFailed
I'm working on doing file uploads using the libs3 library found here: http://libs3.ischo.com/dox/index.html
I'm getting back an error of S3StatusConnectionFailed though. Can someone point me to how this situation could arise? This is my function for uploading files into 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);
}
开发者_如何转开发I get back "Put failed: 46", which I'm pretty sure means that it's an S3StatusConnectionFailed error.
Any help would be great, or even pointers to a boto-like library that I can use instead of the drudgery that is doing this in C++.
Thanks!
Ok, i tried putting non-null value but i was getting same error. i found out the reason for this : you must set the contentLength of "data" (of type put_object_callback_data) as below
fileSize = statBuf.st_size;
//viren+
data.contentLength = fileSize;
//viren-
//..
data.infile = fd;
Oh, and also make sure you have correct permissions set on your bucket.
use NULL for first param in S3_initialize. S3StatusConnectionFailed is indicative that "s3" url maybe wrong. i assume you are providing correct S3_ACCESS_KEY and S3_SECRET_ACCESS_KEY.
精彩评论