cybermatatu / dnd-file-upload

Automatically exported from code.google.com/p/dnd-file-upload
0 stars 0 forks source link

ASP.NET equivalent to Upload.php #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
First of all I want to apologize for making an issue post without having an 
issue.

This is what I did to make an equivalent Upload.php file in ASP.NET using c# 
(c-sharp).

I made a handler to store the files on the server.

*Upload.ashx*
{{{
<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.IO;
using System.Web;

public class Upload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string rootFolder = context.Server.MapPath("~/");
        string fileName = context.Request.Headers["X-File-Name"];
        string saveTo = rootFolder + "folder/" + fileName;

        FileStream writeStream = new FileStream(saveTo, FileMode.Create, FileAccess.Write);

        ReadWriteStream(context.Request.InputStream, writeStream);
    }

    private void ReadWriteStream(Stream readStream, Stream writeStream)
    {
        int Length = 256;
        Byte[] buffer = new Byte[Length];
        int bytesRead = readStream.Read(buffer, 0, Length);

        while (bytesRead > 0)
        {
            writeStream.Write(buffer, 0, bytesRead);
            bytesRead = readStream.Read(buffer, 0, Length);
        }
        readStream.Close();
        writeStream.Close();
    }

    public bool IsReusable
    {
        get { return false; }
    }
}
}}}

Original issue reported on code.google.com by Charme...@gmail.com on 16 Mar 2011 at 11:26

GoogleCodeExporter commented 9 years ago
Seems like Wiki Syntax isn't supported on the issue pages. Disregard the "{{{" 
under the *Upload.ashx* line and the "}}}" at the end.

Original comment by Charme...@gmail.com on 16 Mar 2011 at 11:30

GoogleCodeExporter commented 9 years ago
Thanks Char, very helpful - that cleared some things up wonderfully as I'm new 
to HTML5 dnd & file uploads.

I have everything working well, multiple file uploads and everything, but I am 
getting failures when the source HTML page is on a different domain name than 
the target of the upload.  Do you know why this would be?  

In my javascript, I've triple-verified that the URL is correct, and also 
verified that the receiving server (the target of the upload) is getting the 
HTTP request.  It seems to be failing because from the receiving server's 
perspective, the file stream is empty.  zero length.

I've been scrounging through the code and Googling like mad, but so far I 
haven't found any server settings, or anything related to security 
configurations.  My guess is it's something to do with security and the way 
Firefox 4 handles cross-domain posts?  Any advice you can give is greatly 
appreciated. 

Original comment by michaelp...@gmail.com on 18 May 2011 at 12:33

GoogleCodeExporter commented 9 years ago
Always find it where you last look...
and yes it's a security restriction. 

https://developer.mozilla.org/En/HTTP_Access_Control

Original comment by michaelp...@gmail.com on 18 May 2011 at 12:49

GoogleCodeExporter commented 9 years ago
^^ True indeed. Glad you could use my code :)

Original comment by Charme...@gmail.com on 19 May 2011 at 7:47

GoogleCodeExporter commented 9 years ago
Hi All,

Can someone help with uploading PHP files on Google site?

Best Regards
-Manju
manjusree.ncf@gmail.com

Original comment by manjusre...@gmail.com on 14 Mar 2012 at 6:10

GoogleCodeExporter commented 9 years ago
Can you explain the problem in greater detail?

Original comment by Charme...@gmail.com on 14 Mar 2012 at 8:57

GoogleCodeExporter commented 9 years ago
Hi,

We have booked a site through google site and we are trying to upload
a PHP file to it.

Could you please suggest how to do it.

http://support.google.com/a/?hl=en

Dont option any option to do it.

I am new to the whole process.

Original comment by manjusre...@gmail.com on 14 Mar 2012 at 11:28

GoogleCodeExporter commented 9 years ago
Do you mean that you have made a Google Code Project? And now you are trying to 
upload a single file to the project?

Original comment by Charme...@gmail.com on 20 Mar 2012 at 2:21

GoogleCodeExporter commented 9 years ago
Thank you.

I found what i was looking for.

Thanking you

Original comment by manjusre...@gmail.com on 20 Mar 2012 at 2:29

GoogleCodeExporter commented 9 years ago
Good for you. :)

Original comment by Charme...@gmail.com on 20 Mar 2012 at 3:30

GoogleCodeExporter commented 9 years ago
Thank you. Good for all of us :)

Original comment by manjusre...@gmail.com on 21 Mar 2012 at 4:07