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
Oh, and also make sure you have correct permissions set on your bucket.