Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 619901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:42:17+00:00 2026-05-13T18:42:17+00:00

Trying to upload files using Google Gears and ASP.NET… I assume you can as

  • 0

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:42:18+00:00Added an answer on May 13, 2026 at 6:42 pm

    I think the root of your issue is that with gears your not actually using the multipart-form/data upload mechanism, instead your actually sending your file data in the POST request itself.

    So what you need to do is actually read the request stream from your input handler, and grab the data. Your code should look something like this:

    public void ProcessRequest (HttpContext ctx)
    {
        var filePath = "SomePath/ToWrite/Filedata.dat";
        var stream = ctx.Request.InputStream;
        var buffer = new byte[stream.Length];
        stream.Read(buffer,0,buffer.Lenght);
        using(var fileStream = new FileStream(filePath,FileMode.Create))
        {
            fileStream.Write(buffer, 0, buffer.Length);
        }
    }
    

    Of course whether you write to a file or a database is up to you, as well as exception handling and figuring out whether you want to create a new file or append an existing file, etc. Also, since your code had a 1MB limit on file size, I didn’t bother to limit the buffer length. If your potentially dealing with very large blocks you may need to pick a smaller buffer and read from the stream in chunks until you run out of data (this would be for the case when your stream length was > int.maxvalue, so probably not likely).

    If you need to include things like the name of the original file you have a couple options. One is just to send it with the URL as a query parameter (make sure it’s encoded properly). Then you can read it from ctx.Request.QueryString[“fileName”] or some such.

    Another option would be to put the data you need into a more complex object on the client side, and then use JSON to serialize it all and put it into the POST. So your client code would look something like:

    function uploadFile(file)
    {
        var up = google.gears.factory.create("beta.httprequest");
        up.open("POST", "upload.ashx");
        var fileInfo = { Name: file.name, Data: file.blob, someOtherData: ...};
        up.send(JSON.stringify(fileInfo));
    }
    

    You would need to deserialize it on the server side, so you would most likely need the DataContractJsonSerializer from System.Web.Services. Another option would be the Json.Net library from James Newton-King (http://james.newtonking.com/pages/json-net.aspx).

    internal class FileInfo
    {
        public string Name { get; set; }
        public byte[] Data { get; set; }
        // .. some other data
    }
    
    
    public void ProcessRequest(HttpContext ctx)
    {
        var serializer = new DataContractJsonSerializer(typeof(FileInfo));
        FileInfo fInfo = (FileInfo)serializer.ReadObject(ctx.Request.InputStream);
        var path = basePath + fInfo.Name;
        using(var fileStream = new FileStream(path,FileMode.Create))
        {
            fileStream.Write(fInfo.Data,0,fInfo.Data.Length);
        }
    }
    

    I’m afraid I can’t help much on the PHP side….It’s been a long, long, long time since I’ve been in PHP land 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload files to the blobstore in my Google App without using
I am using CakePHP 2.1 and trying to upload files into server. I can
I am trying to upload a file using Node and Google Docs REST API.
I am trying to upload files via FTP using the following script. The file
I am using railwayjs and I am trying to upload files. I am doing
I am using cakephp 2.1 and i am trying to upload files and how
I'm trying to upload pdf files in the server. And i;m using the following
I'm trying to upload files to server using Uploadify script and then show them
I am getting strange behaviour when trying to upload files, using jQuery multi-file plugin,
I am trying to upload a file in GAE using the Blobstore API. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.