Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a true hack (which would probably break with a new implementation of the AWSSDK), and it requires knowledge of the length of the file being requested, but if you wrap the response stream as shown with <a href="https://gist.github.com/joeenzminger/7460006" rel="nofollow">this class (a gist)</a> as shown below:</p> <pre><code>long length = fileLength; </code></pre> <p>you can get file length in several ways. I am uploading from a dropbox link, so they give me the length along with the url. Alternatively, you can perform a HEAD request and get the Content-Length. </p> <pre><code>string uri = RSConnection.StorageUrl + "/" + container + "/" + file.SelectSingleNode("name").InnerText; var req = (HttpWebRequest)WebRequest.Create(uri); req.Headers.Add("X-Auth-Token", RSConnection.AuthToken); req.Method = "GET"; using (var resp = req.GetResponse() as HttpWebResponse) { using (Stream stream = resp.GetResponseStream()) { //I haven't tested this path Amazon.S3.Transfer.TransferUtility trans = new Amazon.S3.Transfer.TransferUtility(S3Client); trans.Upload(new HttpResponseStream(stream, length), config.Element("root").Element("S3BackupBucket").Value, container + file.SelectSingleNode("name").InnerText); //Use EITHER the above OR the below //I have tested this with dropbox data PutObjectRequest putReq = new PutObjectRequest(); putReq.WithBucketName(config.Element("root").Element("S3BackupBucket").Value); putReq.WithKey(container + file.SelectSingleNode("name").InnerText); putReq.WithInputStream(new HttpResponseStream(stream, length))); //These are necessary for really large files to work putReq.WithTimeout(System.Threading.Timeout.Infinite); putReq.WithReadWriteTimeout(System.Thread.Timeout.Infinite); using (S3Response putResp = S3Client.PutObject(putReq)) { } } } </code></pre> <p>The hack is overriding the Position and Length properties, and returning 0 for Position{get}, noop'ing Position{set}, and returning the known length for Length. </p> <p>I recognize that this might not work if you don't have the length or if the server providing the source does not support HEAD requests and Content-Length headers. I also realize it might not work if the reported Content-Length or the supplied length doesn't match the actual length of the file.</p> <p>In my test, I also supply the Content-Type to the PutObjectRequest, but I don't that that is necessary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload