Groups | Blog | Home
all groups > flash actionscript > september 2004 >

flash actionscript : image upload within flashMX



Stephan Knuesel
9/16/2004 10:41:46 PM
Dear message board readers

i have to create an image upload page within flash. any suggestions on how to
approach it or whether it is possible at all? or do I need to do the upload
part in html/php, sort of in a popup page, and once the image is uploaded flash
loads in the image with loadMovie()?... Also is there a way to scan the hard
drive with flash at all (I assume in collaboration with some server side script?

Any advice appreciated.

Thanks

stephan
Rover
9/16/2004 11:54:18 PM
[quoted text, click to view]

Right now, HTML File Upload is the only way to do this.
chrism59
9/16/2004 11:57:23 PM
I am trying to accomplish the same thing. I have a browse button the allows
the user to select an image from their Hard drive and upload the image. After I
get the image to upload and I know the directory I want the image to be
uploaded. I am trying to perform the upload with a sendAndLoad statement.

var UploadFiles:LoadVars = new LoadVars();
var FileResult:LoadVars = new LoadVars();
UploadFiles.HardDriveImage = "";
UploadFiles.ServerImage. = "";

I set the values
UploadFiles.HardDriveImage = upfile;
UploadFiles.ServerImage = actualpath.
UploadFiles.sendAndLoad("data/upload.cfm",FileResult)

The cfm is as follows:
cfsetting enablecfoutputonly="YES">
<cfcontent type = "application/x-www-urlform-encoded">
<cffile action="upload" destination="#FORM.saveimg#" filefield="#FORM.updir#">
<cfset msg = "Success">
<cfset returnToFlash = "&msg1=#URLEncodedFormat(msg)#">
<!--- FlashOutput contains the string that will be sent back to Flash--->
<cfprocessingdirective suppresswhitespace="Yes">
<cfoutput>
#returnToFlash#
</cfoutput>
</cfprocessingdirective>

I hope this helps. If we both work on the cfm we might make it work.

Patrick Bay
9/17/2004 9:05:13 AM
Hi Chris,

The problem isn't the back end, it's the front end. Flash has no way
to browse local files let alone pass them through the POST method to the
server. HTML uploads are the only way to do this, regardless of how you
receive the file on the other end.

Regards,
Patrick

-----------------------------------------------------
www.baynewmedia.com

IRC (www.dal.net) -> #baynewmedia
-----------------------------------------------------



[quoted text, click to view]
chrism59
9/17/2004 12:14:24 PM
I have to reject this answer. Macromedia produced both Falsh and Coldfusion.
Macromedia claims they can work together. I believe that the problem is that so
many people know other ways of accomplishing a upload that no one is fully
exploring the use of Coldfusion.

If any oue out there can assist with the interaction od flash and coldfusion
Please step up.

IS ANY ONE FROM MACROMEDIA monitoring these discussions? Do you have something
to say? Is it true that you failed to provide this functionality?

For now I will stick with Macromedia's coldfusion.
Patrick Bay
9/17/2004 12:47:29 PM
Ahem...

No, that's a fake. First off, I can see the input field at the
bottom of the page and secondly, I've seen this trick before. While it's
useful, it has nothing to do with Flash except that Flash calls the
Javascript routine to emulate a button click. It's still the browser
that opens the actual dialog box and it's still the browser that
actually send the file. The problem with this method (and the demo
method where I saw this technique used) is that there is no way to
simulate the click of the form's 'upload' button. Furthermore, it
doesn't work in Netscape.

I would hesitate in saying this wasn't possible, only that no one
has yet done it. If you want to save yourself time and headaches, I
would recommend simply popping up a little window with the upload form
in there, maybe surrounded by some Flash. You could even embed a frame
or layer in your main window in which to present the dialog to the user.

However, I would like nothing more than to see you succeed because
I've been trying to find an elegant solution to this for a long time
myself. I sincerely wish you good luck!

Regards,
Patrick

-----------------------------------------------------
www.baynewmedia.com

IRC (www.dal.net) -> #baynewmedia
-----------------------------------------------------



[quoted text, click to view]
chrism59
9/17/2004 1:18:03 PM
Yes flash does have a way to browse local files!!!

I've already completed that part. The user can browse their hard drive and
select the image to upload.

Go to http://www.xplainitmedia.com/upload and enter the user name and
password AA. THIS IS A TEST SITE. then press the replace button and click on a
house. You will go to a screen with a browse button. click on the button and
browse for an image. IT WORKS.

The code will be made available with the CFFILE rename of server files
(already completed) and the deleting if server images. I am only in need of the
upload and the writing of a text file from cf to complete this process.

I will then make it all available thru Macromedia...If I can figure out how to
accomplish that.

The only problem I have is the cf backend on the upload!!!

PLEASE HELP ME WITH THIS
Patrick Bay
9/17/2004 1:57:19 PM
Am I correct in assuming the file is not being uploaded?

Well, file uploads typically don't include path/file names. I don't work
with Coldfusion but I can give you an example with PHP...

When you upload a file, you specify in your browser the file name and
path where it's found on your local machine (browse). When you hit
upload, the data is bundled together and sent to the server using the
POST method. The server receives a number of metadata items including
the file's original name, size, creation date, and temporary location
(where the web server received it).

Simply passing a file name to the script on the server won't do it. The
server has no access to your local drive (at least we hope not!) so what
can it do with that info? It's up to your client (IE/Netscape/etc.) to
send this data to the server. The server is passive in this exchange.

The reason Flash can't do file uploads is because, even if you can
browse local files somehow, it has no way of reading them into memory,
wrapping them in the correct content-type tags, and handing them over to
the server. This is especially true for Flash movies running on the web
because for security reasons they are explicitly forbidden from
accessing the client machine's hard drive.

Currently, only a stand-alone client like IE, Netscape, FTP
applications, etc. are capable of performing this type of operation.

Hope that clears it up :)

Regards,
Patrick


-----------------------------------------------------
www.baynewmedia.com

IRC (www.dal.net) -> #baynewmedia
-----------------------------------------------------



[quoted text, click to view]
Patrick Bay
9/17/2004 3:08:11 PM
Hi,

You're still missing the most important part...PHP and Coldfusion
sit on the server. They do not upload the file, or take the file from
your computer. You computer must send the file to them!
What your movie is receiving is the name of the file on your
computer. To PHP and Coldfusion, which are sitting across the network on
an entirely different computer, this information is meaningless. Your
browser has the ability to send the file to the server, but Flash has no
way to do this. In fact, imagine how dangerous it would be if it could....

Without prompting from the user, Flash could go and grab the
contents of a file on your computer (or guess a file name and try to
grab that) and pass it to the server. The file could contain password
data, personal information, who knows what. Obviously, this is
*extremely* dangerous and therefore not allowed. That's why the file
upload functionality in your browser is so strictly controlled! You can
browse your computer for file names, but that's the extent of it.

Listen, there are quite a few very competent Flash developers out
there. Do you think no one has thought this might be a useful feature?
Unfortunately, there's also been a lot of brainpower that's gone into
preventing just this type of thing from happening simply because it's so
insecure.

Again, I'll say good luck but I wouldn't get my hopes up high!

-----------------------------------------------------
www.baynewmedia.com

IRC (www.dal.net) -> #baynewmedia
-----------------------------------------------------



[quoted text, click to view]
chrism59
9/17/2004 3:27:39 PM
Why is it that everyone tell me this process is impossible and lay the
impossibility at the feet of a part that I have already completed and is
working.

Am I missing something????

Or is it we all, at times, have trouble thinking outside the box. I am
desperately seeking help or an explanation of why it won't work.
Jadon1979
9/17/2004 3:56:31 PM
you stated flashMX generally (version 6 assumed) cant browse files through flash.
chrism59
9/17/2004 4:09:52 PM
I'm using 2004 and it also has no browse functionality. I accomplish the browse
using javascript on a button called Browse
on (release){
getURL("javascript:call_browse();");
}

I have a frame page top bottom with the top set at 100% containing the flash
move and the bottom set at 0% the bottom page has a cf filefield and the
following javascript in the header
<script language="javascript">
function set_variable(value) {
parent.mainFrame.movie.SetVariable("uploadfile",value);
}
</script>
All javascript was based on a download created by Dennis Baldwin, it didn't
work in mx 2004.

The top page has the following javascript in the header:
<script language="javascript">

function call_browse(){
parent.bottomFrame.form.file.click();
parent.bottomFrame.form.file.focus();
}

</script>
This process allow the user to browse for a file and returns the complete
path to flash.

Now I have the path and name of the file for uplaoding...I have the server
location and name where I wnat the file placed...I can pass both of these to a
cfm page. I just can't get the fcm page to work.

Please
chrism59
9/17/2004 5:30:35 PM
Can you explain?

After the user select a file I have a complete path/name for the image. I use
that path/name to display the image in flash.

Why is that path/file not valid when passed to a cffile upload?
chrism59
9/17/2004 6:26:58 PM
No, This only adds tot he confusion.

I can open my movie in IE from the server.(web address above with test
username and password)

I can click the browse button in flash and select an image from my hard drive.
I can then load the image into my web base flash movie based on the information
returned by the user.

If my web based flash movie can do that shouldn't I be able to pass the file
information that the user selected from their hard drive to maybe... a
filefield (hidden) on my webpage.

Then call a method...say php (I know nothing of php) or coldfusion and have it
upload the file from the hidden filefield.

The action can take part outside of flash and yet be controlled by flash?

I know I'm pushing the envelop here but there has to be a way.

When the user pressed the browse button in flash java does click the browse
button for a hidden filefield. When the user select the image to upload the
file information IS being passed back to flash.

image_mc .loadMovie(filefield)

loads the image in the web based flash movie.

THERE HAS TO BE A WAY TO USE THIS filefield to upload the file.
chrism59
9/17/2004 8:35:01 PM
Patrick,
IT WORKS!!!!!

I understand that I am really uploading the file using Coldfusion, but to the
user it looks like the flash application is doing it and the flash
functionality can still be brought into the process.

I have now successfully uploaded a file using flash as the user interface!!!!!
I still have a lot of questions but I can see the file I uploaded on my server
at the ISP.
The major problem right now is the upload button triggers the hidden for
submit. The progress bar at the bottom of the browse window moves half way
across and stops. It however does not change the fact THE FILE WAS UPLOADED!!!

When I get the rest of the bugs out I will make this available to all!!.

If anyone can start me in the right direction to fix the progress bar I would
be very grateful.

chrism59
9/18/2004 5:44:05 PM
I have posted a working copy of the file upload code. Searc for Flash File
Upload

Thany you to all who helped. I and included a detailed Read me and there are
still issues that need to be addressed. You help is welcome
AddThis Social Bookmark Button