简体   繁体   English

从我的应用程序(Indy / Delphi)发送文件到ASP页面然后到另一台服务器(Amazon S3)

[英]Sending a file from my application (Indy/Delphi) to an ASP page and then onto another server (Amazon S3)

I have a need to store files on Amazon AWS S3, but in order to isolate the user from the AWS authentication I want to go via an ASP page on my site, which the user will be logged into. 我需要在Amazon AWS S3上存储文件,但是为了将用户与AWS身份验证隔离,我想通过我的站点上的ASP页面进行访问,用户将登录该页面。 So: 所以:

The application sends the file using the Delphi Indy library TidHTTP.Put (FileStream) routine to the ASP page, along with some authentication stuff (mine, not AWS) on the querystring. 应用程序使用Delphi Indy库TidHTTP.Put(FileStream)例程将文件发送到ASP页面,以及查询字符串上的一些身份验证内容(我的,而不是AWS)。

The ASP page checks the auth details and then if OK stores the file on S3 using my Amazon account. ASP页面检查auth详细信息,然后如果OK,则使用我的Amazon帐户将文件存储在S3上。

Problem I have is: how do I access the data coming in from the Indy PUT using JScript in the ASP page and pass it on to S3. 我遇到的问题是:如何使用ASP页面中的JScript访问来自Indy PUT的数据并将其传递给S3。 I'm OK with AWS signing, etc, it's just the nuts and bolts of connecting the two bits (the incoming request and the outgoing AWS request) ... 我可以使用AWS签名等,这只是连接两个位(传入请求和传出AWS请求)的基本要点......

TIA R TIA R

A HTTP PUT will store the file at the given location in the HTTP header - it "requests that the enclosed entity be stored under the supplied Request-URI". HTTP PUT将文件存储在HTTP头中的给定位置 - 它“请求将所包含的实体存储在提供的Request-URI下”。

The disadvantage with the PUT method is that if you are on a shared hosting environment it may not be available to you. PUT方法的缺点是,如果您在共享托管环境中,则可能无法使用它。

So if the web server supports PUT, the file should be available at the given location in the the (virtual) file system. 因此,如果Web服务器支持PUT,则该文件应该在(虚拟)文件系统中的给定位置可用。 The PUT request will be handled by the server and not ASP: PUT请求将由服务器而不是ASP处理:

In the case of PUT, the web server handles the request itself: there is no room for a CGI or ASP application to step in. The only way for your application to capture a PUT is to operate on the low-level, ISAPI filter level 在PUT的情况下,Web服务器自己处理请求:CGI或ASP应用程序没有空间介入。应用程序捕获PUT的唯一方法是在低级别的ISAPI过滤器级别上运行

http://www.15seconds.com/issue/981120.htm http://www.15seconds.com/issue/981120.htm

Are you sure you need PUT and can not use a POST, which will send the file to a URL where your ASP script can read it from the request stream? 您确定需要PUT并且不能使用POST,它会将文件发送到您的ASP脚本可以从请求流中读取它的URL吗?

OK, Ive got a bit further with this. 好的,我对此有所了解。 Code at the ASP end is: ASP端的代码是:

    var PostedDataSize   = Request.TotalBytes ;
    var PostedData       = Request.BinaryRead (PostedDataSize) ;

    var PostedDataStream = Server.CreateObject ("ADODB.Stream") ; 
    PostedDataStream.Open ;
    PostedDataStream.Type = 1 ;                    // binary
    PostedDataStream.Write (PostedData) ;

    Response.Write ("PostedDataStream.Size = " + PostedDataStream.Size + "<br>") ;

    var XML = AmazonAWSPUTRequest (BucketName, AWSDestinationFileID, PostedDataStream) ;
    .....

    function AmazonAWSPUTRequest (Bucket, Filename, InputStream) 

    {
    ....
    XMLHttp.open ("PUT", URL + FRequest, false) ;

    XMLHttp.setRequestHeader (....
    XMLHttp.setRequestHeader (....
    ...
    Response.Write ("InputStream.Size = " + InputStream.Size + "<br>") ;
    XMLHttp.send (InputStream)  ;     

So I use BinaryRead, write it to a binary stream. 所以我使用BinaryRead,将其写入二进制流。 If I write out the size of the stream I get the size of the file I POST'ed from my application, so I reckon the data is in there somewhere. 如果我写出流的大小,我得到我从应用程序POST的文件的大小,所以我认为数据在某处。 I then call a routine (with the stream as a parameter) which sets up the AWS authentication/signing and does a PUT. 然后我调用一个例程(使用流作为参数)来设置AWS身份验证/签名并执行PUT。

The AWS call returns no errors and a file of the correct name is created in the right place, but it has a size of zero! AWS调用不返回任何错误,并且在正确的位置创建了正确名称的文件,但其大小为零! InputStream.Size has a value the same as the stream parameter passed to the routine - ie the size of the original file. InputStream.Size的值与传递给例程的stream参数相同 - 即原始文件的大小。

Any ideas? 有任何想法吗?

POSTSCRIPT. 后记。 Found the problem. 发现了问题。 It's caught me a few times with streams, this one. 它让我抓住了几次溪流,这一次。 When you write data to a stream, don't forget to reset the stream position back to zero before trying to read from the stream again. 将数据写入流时,不要忘记在尝试再次从流中读取之前将流位置重置为零。 Ie just before the line: 就在排队之前:

    XMLHttp.send (InputStream)  ; 

I needed to add: 我需要补充一下:

   InputStream.Position = 0 ;

My thanks for the interest and suggestions. 我感谢您的兴趣和建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM