472,989 Members | 2,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

How to upload an <img> content without <input type=file > ?

Hi all,

I wonder is it possible to upload the content of an <imgfield to a server.
The content of the <imgwas downloaded from a web site different from the
one it should be uploaded. The image file should not be saved locally before
uploading. It should not be visible any <input type=file on the form.
How can it be done?

I'm working on a project where client javascript requests an image server to
generate dynamic images. The client selects the image it wants and uploads
this to another server which stores the image. I know it is very simple to
upload a file to a server by using <input type=file but it is not the
case. The image I need to uploaded is stored on a <img field and is not
saved to local file system.

Any hint is welcomed
Thanks in advance
Sammy
Jan 12 '07 #1
4 8975
Rik
SammyBar wrote:
Hi all,

I wonder is it possible to upload the content of an <imgfield to a
server. The content of the <imgwas downloaded from a web site
different from the one it should be uploaded. The image file should
not be saved locally before uploading. It should not be visible any
<input type=file on the form.
How can it be done?

I'm working on a project where client javascript requests an image
server to generate dynamic images. The client selects the image it
wants and uploads this to another server which stores the image. I
know it is very simple to upload a file to a server by using <input
type=file but it is not the case. The image I need to uploaded is
stored on a <img field and is not saved to local file system.

Any hint is welcomed
Thanks in advance
Well, if the file 'should not be saved locally' and 'was downloaded from a
website' (which is a contradiction btw), I assume passing the url of the
image file to a server side script should suffice. Do this in either a text
or a hidden <input>. As long as the image file is online somewhere
retrieving and manipulating it is a piece of cake for most server side
languages.
--
Rik Wasmus
Jan 12 '07 #2
Interesting request. I'd say you need to research two things first.
Read through the RFC that covers how the file upload control works
(http://www.ietf.org/rfc/rfc1867.txt), and maybe the w3c mention of it
(http://www.w3.org/TR/html4/interact/forms.html). After that consider
setting up a test upload form and receiving script on your server,
sniff your connection using ethereal or similar, and do an upload. This
should give you a solid understanding of what exactly the server
expects.

Now I'll take a theoretical stab at a solution. AFAIK there is now way
in javascript to access that actual image raster data, just properties
of the img element such as src. What I think might work is this:

1. When the user selects the image they want, get the url of it in JS
via the src property.
2. Dispatch a request using AJAX to the server for that image. This is
where it starts to get tricky since the server will respond with raw
image data (JPG/PNG/GIF) and the corresponding MIME type, and as such
the browser will probably not populate either the responseText or
responseXML. However you may be able to access the image data via
responseBody property - I'm not sure.
The other alternative here is to have the server serve images
indirectly through a script (that reads and dumps the image data). The
server script could search for a certain header, which your AJAX
request would have to set, and when it sees that header, dump the image
data as a base64 encoded string and use text/plain as the MIME type.
When your xmlhttp object gets a response, it will have the base64
encoded image in the responseText property, which you can then post to
the server as a normal form (that is, without the
enctype="multipart/form-data").
3. The server receiving the posted image data will need to know that
its receiving base64 image data, so you'd need to set some headers in
your AJAX post. The server would then know to decode the string back to
it's original binary format - the image.

Let me know how you progress with this - if I ever get a break i may
have to take a crack at it.

SammyBar wrote:
Hi all,

I wonder is it possible to upload the content of an <imgfield to a server.
The content of the <imgwas downloaded from a web site different from the
one it should be uploaded. The image file should not be saved locally before
uploading. It should not be visible any <input type=file on the form.
How can it be done?

I'm working on a project where client javascript requests an image server to
generate dynamic images. The client selects the image it wants and uploads
this to another server which stores the image. I know it is very simple to
upload a file to a server by using <input type=file but it is not the
case. The image I need to uploaded is stored on a <img field and is not
saved to local file system.

Any hint is welcomed
Thanks in advance
Sammy
Jan 12 '07 #3
So I just read Rik's response, which showed how complicated an answer
mine was to a simple problem. Do what he said: communicate the URL of
the image from one server to the other, and let the server receiving
the url download it directly. Forget the forms bit - just tell the
server the url of the desired img.

Rik wrote:
SammyBar wrote:
Hi all,

I wonder is it possible to upload the content of an <imgfield to a
server. The content of the <imgwas downloaded from a web site
different from the one it should be uploaded. The image file should
not be saved locally before uploading. It should not be visible any
<input type=file on the form.
How can it be done?

I'm working on a project where client javascript requests an image
server to generate dynamic images. The client selects the image it
wants and uploads this to another server which stores the image. I
know it is very simple to upload a file to a server by using <input
type=file but it is not the case. The image I need to uploaded is
stored on a <img field and is not saved to local file system.

Any hint is welcomed
Thanks in advance

Well, if the file 'should not be saved locally' and 'was downloaded from a
website' (which is a contradiction btw), I assume passing the url of the
image file to a server side script should suffice. Do this in either a text
or a hidden <input>. As long as the image file is online somewhere
retrieving and manipulating it is a piece of cake for most server side
languages.
--
Rik Wasmus
Jan 12 '07 #4
SammyBar said the following on 1/12/2007 9:54 AM:
Hi all,

I wonder is it possible to upload the content of an <imgfield to a server.
The content of the <imgwas downloaded from a web site different from the
one it should be uploaded. The image file should not be saved locally before
uploading. It should not be visible any <input type=file on the form.
How can it be done?
You can't. The image is locally though in the cache as long as the
current page is open.
I'm working on a project where client javascript requests an image server to
generate dynamic images. The client selects the image it wants and uploads
this to another server which stores the image. I know it is very simple to
upload a file to a server by using <input type=file but it is not the
case. The image I need to uploaded is stored on a <img field and is not
saved to local file system.
It is not "saved" but it is in the cache. And you aren't going to be
able to set the value of a file input so you can't do it
programatically. The user is going to have to choose that image to be
uploaded.

If the images are random then you are kind of hosed. If the images are
dynamic yet predictable then you simply give your server the parameters
to get the image on its own.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in -...
8
by: slim | last post by:
hi again all, i am still working on the website as mentioned in earlier threads and have hit another snag... http://awash.demon.co.uk/index.php http://awash.demon.co.uk/vd.css the php is...
2
by: Kimmo R. M. Hovi | last post by:
Currently I have defined: -- clip clip -- <form method="post" action="xx" enctype="application/x-www-form-urlencoded"> <input type="image" name="Function 1" src="image1.gif" border="0"...
8
by: KS | last post by:
Just to show some code to show the consept. <img id="date" onclick="javascript:show_calendar();" src="/PlexSysWeb/images/show-calendar.gif" width=20 height=18 border=0> What i want the...
22
by: David. E. Goble | last post by:
Hi All; I have a few of these; sigsImages="sigs/finished1.jpg" sigsImages="sigs/foghorn.jpg" lower I have;
2
by: ThePsudo | last post by:
# SIMPLE VERSION # Is there a way I can create a new <img> tag onClick? # DETAILED VERSON # I'm making a game that involves drawing a path between two points on a grid. I've got the...
10
by: Brian Henry | last post by:
Hi, I am having a problem with an attachment system I made... it works with files up to ~3MB in size then after that if you try to upload a file it just goes to a "Page can not be displayed" page...
17
by: Alan Silver | last post by:
Hello, I have a page which I am converting to use themes. The page has an HTML <input type="image"> element that is used to post to another page. I would like to replace this with a server...
3
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image'...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.