c# - HttpPostedFileBase Stream Upload to AWS SDK Bucket has no Data -


i'm testing how upload aws using sdk sample .txt file web app. file uploads bucket, downloaded file bucket empty notepad document without text original uploaded file. i'm new working streams, i'm not sure wrong here. see why data wouldn't sent in transfer request? in advance!

using (var client = new amazons3client(amazon.regionendpoint.uswest1)) {     //save file bucket     using (filestream txtfilestream = (filestream)uploadedhttpfilebase.inputstream)     {         try         {             transferutility filetransferutility = new transferutility();             filetransferutility.upload(txtfilestream, bucketlocation,                  uploadedhttpfilebase.filename);         }         catch (exception e)         {             e.message.tostring();         }     } } 

edit:

both transferutility , putobjectrequest/putobjectresponse/amazons3client.putobject saved blank text file. then, after having trouble instantiating new filestream, memorystream used after resetting starting position 0 still saved blank text file. ideas?

new code:

using (var client = new amazons3client(amazon.regionendpoint.uswest1)) {     stream saveablestream = new memorystream();     using (stream source = (stream)uploadedhttpfilebase.inputstream)     {         source.position = 0;         source.copyto(saveablestream);     }      //save file bucket                                             try     {         putobjectrequest request = new putobjectrequest         {             bucketname = bucketlocation,             key = uploadedhttpfilebase.filename,              inputstream = saveablestream         };         putobjectresponse response = client.putobject(request);     }     catch (exception e)     {         e.message.tostring();     } } 

most transferutility doesn't work temporary upload files. try copy input stream somewhere (e.g. other not-so-temporary file, or memorystream if you're sure not give outofmemory @ point). thing rid of transferutility , use low-level amazons3client.putobject finer control on stream lifetime (do not forget you'll need implement retrying s3 api prone returning random temporary errors).


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -