Solved

Upload from URL, not local file system

Posted on 2008-10-02
4
217 Views
Last Modified: 2013-11-07
Have to admit, I know nothing about .NET and come from a classic ASP world as far as server-side programming goes... Anyway.

What we're looking to do is to upload an image from a user provided URL to server, rather than prompting user for a file on their computer.

To demonstrate behaviour:
have a look at http://imageshack.us/

upload: http://img.youtube.com/vi/PTU2He2BIc0/default.jpg

results in the image being hosted at:

http://img440.imageshack.us/img440/8094/defaultgh3.jpg

The company that I now work for is a .NET shop that has recently migrated to 2.0 and uses a third party component http://www.powupload.com/ for it's current uploading needs.

Thanks for your thoughts.

N
0
Comment
Question by:steam23
4 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 22630395
to do this you would just use a TextBox to enter the URL, then when a button is clicked you would get the server to retrieve the file at the given URL

eg


void UploadHandler(object sender, eventargs e)
{
   if(Textbox1.text != string.empty)
   {
      System.Net.WebClient c = new System.Net.WebClient();
      byte[] imageBytes = c.DownloadData(TextBox1.Text);
      //now save imagebytes or whatever
   }
 
}

Open in new window

0
 

Author Comment

by:steam23
ID: 22630457
I guess this would be customizing of how powupload handles being passed a string?
0
 
LVL 10

Accepted Solution

by:
GeoffSutton earned 250 total points
ID: 22634731
No... that would bypass powerupload altogether :)  Also if you are going to be uploading the file from a local URL you would probably want to add Javascript to resolve mapped drives:
This will take care of that, although it requires using activeX not marked as safe.  It will need to be rewritten for Firefox (I wrote it for an intranet situation).

Once you have the byte stream you should be able to take the stream and channel it directly into the database "Image" column, along with additional metadata.  Then you can stream the data out again simply.  Using this method you are not limited to just images either:  You can store video, audio or any other Binary.  All you need do is make sure you have the MIME content type stored so you can set that on the output page.

Doing this should speed the process some, since right now it seems fairly slow.

Hope this helps,
Geoff

   function getUNCPath(){
            var file1=document.getElementById("file1");
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var path=file1.value;
            var strDrive;
            var strShare;
            strDrive=fso.GetDriveName(path);
            strShare=fso.Drives(strDrive).ShareName;
            var unc=path.replace(strDrive,strShare);
            document.getElementById("uncPath").value=unc;
            return;
        }

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question