嘗試使用Google Gears和ASP.NET上傳文件...我假設您可以接受blob。使用Google Gears和ASP.NET或PHP上傳文件
我在頁面中有FileUpload控件。
<asp:FileUpload runat="server" ID="File1" />
然後JavaScript的
var file1 = document.getElementById("<%# File1.ClientID %>");
var desktop = google.gears.factory.create('beta.desktop');
file1.onclick = function()
{
desktop.openFiles(openFilesCallback,
{
singleFile: true,
filter: ["image/jpeg"]
}
);
return false;
}
function openFilesCallback(files)
{
if(files.length == 0)
{
alert("No files selected");
}
else
{
// 1MB = 1024 * 1024 bytes
if(files[0].blob.length > (1024 * 1024))
{
alert("File '" + files[0].name + "' is too big to upload");
}
else
{
uploadFile(files[0]);
}
}
}
function uploadFile(file)
{
var up = google.gears.factory.create("beta.httprequest");
up.open("POST", "upload.ashx");
up.send(file.blob);
}
但是,我不知道如何處理它的處理程序。
public void ProcessRequest (HttpContext ctx)
{
ctx.Response.ContentType = "text/plain";
ctx.Response.Write("Hello World");
ctx.Response.Write(ctx.Request.Files.Count.ToString());
ctx.Response.Write(ctx.Request.Form.Count.ToString());
}
如果我設置一個斷點在任的最後兩個語句,既Files.Count
和Form.Count
返回0。當我沒有我得到在Firebug的異常:Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED)
如果我不能使用POST通過Gears上傳,可以使用PUT完成嗎?
編輯: PHP代碼將被罰款,以及(因爲我想這樣做,在這兩種語言)
謝謝,似乎工作(它已經使用多部分形式/數據,所以這不是問題)。雖然不是使用JSON並反序列化數據,但我正在爲其他元數據設置請求標頭。 – SamWM 2010-02-19 10:29:46