473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file upload with JSON+AJAX?

kj

I would like to convert a form that currently uses the traditional
CGI sequence (i.e. the action associated with the form sends a POST
request to a server-side CGI script) to one that uses AJAX to send
a JSON-encoded request to a remote web service.

The stumbling block I'm running into is that one of the inputs in
the form is a file upload element, and I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?

TIA!

Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Jun 27 '08 #1
11 8388
VK
On May 8, 12:14 am, kj <so...@987jk.co m.invalidwrote:
I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?
No. XHR doesn't allow local file access, so for the file upload you
have to use traditional forms.
Jun 27 '08 #2
VK wrote:
On May 8, 12:14 am, kj <so...@987jk.co m.invalidwrote:
>I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?

No. XHR doesn't allow local file access,
It does when running locally.
so for the file upload you have to use traditional forms.
Correct.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #3
Thomas 'PointedEars' Lahn wrote:
VK wrote:
>On May 8, 12:14 am, kj <so...@987jk.co m.invalidwrote:
>>I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?
No. XHR doesn't allow local file access,

It does when running locally.
It also does when running via HTTP, and the required privileges are granted,
or when running out of the sandbox.

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jun 27 '08 #4
kj
In <48************ @PointedEars.de Thomas 'PointedEars' Lahn <Po*********@we b.dewrites:
>Thomas 'PointedEars' Lahn wrote:
>VK wrote:
>>On May 8, 12:14 am, kj <so...@987jk.co m.invalidwrote:
I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?
No. XHR doesn't allow local file access,

It does when running locally.
>It also does when running via HTTP, and the required privileges are granted,
or when running out of the sandbox.
I'm not familiar with either of these two possibilities. I'm
particularly intrigued by the first one. How can a web app request
the necessary privileges?

Thanks in advance!

Kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Jun 27 '08 #5
On May 8, 9:43 am, kj <so...@987jk.co m.invalidwrote:
In <48222DD6.40... @PointedEars.de Thomas 'PointedEars' Lahn <PointedE...@we b.dewrites:
Thomas 'PointedEars' Lahn wrote:
VK wrote:
On May 8, 12:14 am, kj <so...@987jk.co m.invalidwrote:
I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?
No. XHR doesn't allow local file access,
It does when running locally.
It also does when running via HTTP, and the required privileges are granted,
or when running out of the sandbox.

I'm not familiar with either of these two possibilities. I'm
particularly intrigued by the first one. How can a web app request
the necessary privileges?
A web app can't programatically request the necessary privileges. The
user needs to either set preferences in his browser or grant
premission to do it. Obviously not all browsers have a let-really-
dangerous-code-access-my-harddisk preference to set. I believe you can
enable such a feature in firefox using about:config.
Jun 27 '08 #6
slebetman wrote:
On May 8, 9:43 am, kj <so...@987jk.co m.invalidwrote:
>In <48222DD6.40... @PointedEars.de Thomas 'PointedEars' Lahn <PointedE...@we b.dewrites:
>>Thomas 'PointedEars' Lahn wrote:
VK wrote:
On May 8, 12:14 am, kj <so...@987jk.co m.invalidwrote:
>I can't figure out how to
>include the data from the specified file in the JSON payload. Is
>there a way to do this?
No. XHR doesn't allow local file access,
It does when running locally.
It also does when running via HTTP, and the required privileges are granted,
or when running out of the sandbox.
I'm not familiar with either of these two possibilities. I'm
particularly intrigued by the first one. How can a web app request
the necessary privileges?

A web app can't programatically request the necessary privileges.
Yes, it can. I have posted a proof-of-concept here before.
The user needs to either set preferences in his browser or grant
premission to do it.
As for the latter, that is why it is called a privilege *request*.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Jun 27 '08 #7
On 7 May, 20:14, kj <so...@987jk.co m.invalidwrote:
The stumbling block I'm running into is that one of the inputs in
the form is a file upload element, and I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?
There is a way to achieve the effect. I pointed out in a recent
discussion on this forum that Google Mail performs an AJAX type upload
of attachments. If you search back for the discussion, I think you'll
find that the solution had something to do with using an iframe.

http://groups.google.co.uk/group/com...91d5edba814a5b
Jun 27 '08 #8
On 8 May, 10:49, Captain Paralytic <paul_laut...@y ahoo.comwrote:
On 7 May, 20:14, kj <so...@987jk.co m.invalidwrote:
The stumbling block I'm running into is that one of the inputs in
the form is a file upload element, and I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?

There is a way to achieve the effect. I pointed out in a recent
discussion on this forum that Google Mail performs an AJAX type upload
of attachments. If you search back for the discussion, I think you'll
find that the solution had something to do with using an iframe.

http://groups.google.co.uk/group/com...rowse_frm/thre...
Here is sample code:
http://www.ajaxonomy.com/2008/ajax/u...asynchronously
Jun 27 '08 #9
Captain Paralytic wrote:
On 8 May, 10:49, Captain Paralytic <paul_laut...@y ahoo.comwrote:
>On 7 May, 20:14, kj <so...@987jk.co m.invalidwrote:
>>The stumbling block I'm running into is that one of the inputs in
the form is a file upload element, and I can't figure out how to
include the data from the specified file in the JSON payload. Is
there a way to do this?
There is a way to achieve the effect. I pointed out in a recent
discussion on this forum that Google Mail performs an AJAX type upload
of attachments. If you search back for the discussion, I think you'll
find that the solution had something to do with using an iframe.

http://groups.google.co.uk/group/com...rowse_frm/thre...

Here is sample code:
http://www.ajaxonomy.com/2008/ajax/u...asynchronously
While it certainly is possible, although not generally feasible, to upload
local files *through XHR*, on a closer look you will realize that this
solution is _not_ what was being asked for. Instead, it implements the
already proposed solutions of using a (static or dynamically generated;
here the former) HTML form to submit the information. The only real
difference to a non-scripted form is that the form is submitted with
scripting.

The very resource you have referred to correctly confirms that:

| How to upload files asynchronously?
|
| As I described above You can’t upload files using AJAX. Some time ago I
| wrote a JavaScript file upload object which as You already understood can
| help developers make forms which upload files asynchronously. [...]
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jun 27 '08 #10

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

Similar topics

3
2083
by: kariach | last post by:
Hello, I am writing a web app that collects some user input and an optional image filename. When the user clicks submits, I use an asynchronous XML HTTP call to a backend asp.net handler to process the input. I have not been able to figure out clean way to upload a file in this setup - Can someone offer some help? thanks, Simon
2
2205
by: itsmesuraj | last post by:
Hi, I’m trying to create an application with AJAX which would upload a file on to the server. Am sending the request through the browser to the Servlet which uses the commons.io.FileUpload API. I have constructed the request body as follows.... var boundaryString = 'AaB03x'; var boundary = '--' + boundaryString; var requestbody = boundary + '\n' + 'Content-Disposition: form-data; name="attachmentName"' + '\n' + '\n' +...
1
1845
by: JagPeram | last post by:
Can Anyone tell me how to upload file using ajax with struts framework?
1
1413
by: pritisolank | last post by:
Hello everyone, I am trying to do ajax file upload i am half way and now i don't find any way to reach :-( can someone tell me how to do a file upload in ajax+PHP. regards, priti
6
2770
by: newlearner | last post by:
hi, im trying to upload a file using ajax and php. im not able to get the $FILES and $FILES. But when i try it out in the traditional format its works good. but when i try it out in ajax im not able to get these values. I use POST method and the requestHeader's content type is set as multipart/form-data. Looking forward .....
1
1550
by: kmithu | last post by:
Hi friends, I want to upload a file on AJAX web page. The HTML code i m using is: ---------------------------------------------------------------------------------------- <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
5
3135
dmjpro
by: dmjpro | last post by:
Hi Experts! I have been working with Ajax for there four months. But today suddenly come to my mind that if I want to upload the Image File using Ajax then what will be URL? Could some help me? Then please Help me! Kind regards, Dmjpro.
3
4497
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
1
3945
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image plz help how i can do this the...
6
2158
vikysaran
by: vikysaran | last post by:
Hi, Please check the attachment http://www.golsinc.com/app7/AJAXEnabledWebSite.zip Here i made a small application for file upload. Made a huge form and need image upload without page refresh here. i tried a lot, searched over net but finally my page is posting back on button click. If i dont use <Triggers> <asp:PostBackTrigger ControlID="Button1" /> </Triggers>
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.