Trying to upload files using Google Gears and ASP.NET... I assume you can as the HttpRequest API accepts blobs.
I have FileUpload control in the page.
<asp:FileUpload runat="server" ID="File1" />
Then the 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);
}
However, I am not sure how to handle it in the handler.
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());
}
If I set a breakpoint on either of the last two statements, both Files.Count
and Form.Count
return 0. When I don't I get an exception in Firebug: Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED)
If I can't use POST to upload via Gears, can it be done using PUT?
Edit: PHP Code will be fine as well (since I want to do it in both languages)