tags:

views:

16

answers:

0

Hi, I want to upload to s3 using vc++, i use libs3 but i am not able to upload single xml file on s3 bucket can anyone tell what is the problem really i am not getting ... i am able to create a bucket.

unsigned __stdcall S3Operation( void* pArguments ) 
{ 
try 
{ 
typedef void (__stdcall *CREATE_BUCKET)(S3Protocol , const char *,const char *, 
const char *,S3CannedAcl,const char *, 
S3RequestContext *,const S3ResponseHandler *, 
void *); 
typedef S3Status (__stdcall *INIT)( const char*,int); 

typedef void (__stdcall *DEINITIALIZE)(); 
typedef void (__stdcall *PUTOBJECT)(const S3BucketContext *, 
const char *,uint64_t, 
const S3PutProperties *, 
S3RequestContext *, 
const S3PutObjectHandler *, 
void *); 


typedef int (__stdcall *STATUSRETRY)(S3Status); 

HINSTANCE hModule = (HINSTANCE)LoadLibrary(TEXT("libs3.dll")); 
INIT proc = (INIT)GetProcAddress(hModule,"S3_initialize"); 
S3Status status; 
if(proc) 
{ 
char bucketName[] = "PrabhatBucket"; 
const char *locationConstraint = 0; 
S3CannedAcl cannedAcl = S3CannedAclPublicRead ; 

S3ResponseHandler responseHandler = 
{ 
&responsePropertiesCallback, &responseCompleteCallback 
}; 

status = (proc)("", S3_INIT_ALL); 
int nRetry = 0; 
do { 
CREATE_BUCKET procCreateBucket = (CREATE_BUCKET)GetProcAddress(hModule,"S3_create_bucket"); 
(procCreateBucket)(protocolG, "OUR KEY", bucketName,cannedAcl, 0, 0,&responseHandler, 0); 
STATUSRETRY procStatusRetry = (STATUSRETRY)GetProcAddress(hModule,"S3_status_is_retryable"); 
S3Status status; 
nRetry = (procStatusRetry)(status); 
} while (nRetry && should_retry()); 


if (statusG != S3StatusOK) 
{ 
AfxMessageBox(L"buckect create Fail"); 
} 


S3BucketContext bucketContext = 
{ 
bucketName, 
protocolG, 
uriStyleG, 
"OUR_KEY" 
}; 


const char filename[] = "c:\\url_20091119102308.xml"; 

const char objName[] = "url_20091119102308.xml"; 

uint64_t contentLength = 0; 
const char *cacheControl = 0, *contentType = 0, *md5 = 0; 
const char *contentDispositionFilename = 0, *contentEncoding = 0; 
int64_t expires = -1; 
int metaPropertiesCount = 0; 
S3NameValue metaProperties[S3_MAX_METADATA_COUNT] = {0}; 
int noStatus = 0; 
put_object_callback_data data; 

/*char *param = 0; 

cacheControl = "Cache-Control";*/ 

contentType = "application/xml"; 

//contentDispositionFilename = filename; 

//md5 = "base64-encoded"; 

//metaProperties[S3_MAX_METADATA_COUNT].name = "x-amz-meta-foo";*/ 

data.infile = 0; 
data.gb = 0; 
data.noStatus = 0;//noStatus; 

if (filename) 
{ 
if (!contentLength) 
{ 
struct stat statbuf; 
// Stat the file to get its length 
if (stat(filename, &statbuf) == -1) 
{ 
fprintf(stderr, "\nERROR: Failed to stat file %s: ", 
filename); 
perror(0); 
exit(-1); 
} 
contentLength = statbuf.st_size; 
} 
// Open the file 
if (!(data.infile = fopen(filename, "r" FOPEN_EXTRA_FLAGS))) 
{ 
fprintf(stderr, "\nERROR: Failed to open input file %s: ", 
filename); 
perror(0); 
exit(-1); 
} 
} 

data.contentLength = data.originalContentLength = contentLength; 





S3PutProperties putProperties = 
{ 
contentType, 
md5, 
cacheControl, 
contentDispositionFilename, 
contentEncoding, 
expires, 
cannedAcl, 
metaPropertiesCount, 
metaProperties 
}; 

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

nRetry = 0; 
do { 
PUTOBJECT procPutObject = (PUTOBJECT)GetProcAddress(hModule,"S3_put_object"); 
(procPutObject)(&bucketContext,filename, contentLength, &putProperties, 0, 
&putObjectHandler, &data); 
STATUSRETRY procStatusRetry = (STATUSRETRY)GetProcAddress(hModule,"S3_status_is_retryable"); 
S3Status status; 
nRetry = (procStatusRetry)(status); 
//throws error about S3 status : email address too long 
} while (nRetry && should_retry()); 


//Getting error S3StatusServerFailedVerification 
if (statusG != S3StatusOK) { 
AfxMessageBox(L"Put Object Fail"); 
} 
} 
} 
catch(...) 
{ 
return 0; 
} 
}