Solved

Upload from URL, not local file system

Posted on 2008-10-02
4
215 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now