PDA

View Full Version : flash upload / download problem


Planche
01-09-2007, 12:58 PM
I'm developing a small upload application, for personal user and I keep getting an HTTP Error 403. This is the code I'm using for this:


System.security.allowDomain("http://localhost/", "127.0.0.1");
//import the FileReference Object
import flash.net.FileReference;
//initial settings
upload_btn.enabled = false;
//the FileReference object
var file_fr:FileReference = new FileReference();
//object for listening to for FileReference events
var list_obj:Object = new Object();

list_obj.onSelect = function() {
upload_btn.enabled = true;
name_txt.text = file_fr.name;
};
/*
list_obj.onProgress = function(bytesTotal, bytesLoaded) {
var percent = bytesLoaded/file_fr.size;
};
*/
//if a user selects cancel
list_obj.onCancel = function() {
debug_txt.text = "Cancel was selected";
};
//if there is an IO error
list_obj.onIOError = function(fileRef) {
debug_txt.text += "IO error with "+fileRef.name;
};
//security error problem
list_obj.onSecurityError = function(fileRef, error) {
debug_txt.text += "Security error with "+fileRef.name+":"+error;
};
//httpError
list_obj.onHTTPError = function(fileRef:FileReference, error:Number) {
debug_txt.text += "HTTP error: with "+fileRef.name+":error #"+error;
};
// complete
list_obj.onComplete = function(fileRef:FileReference) {
downloadImage(fileRef.name);
debug_txt.text += "All Done";
upload_btn.enabled = false;

};
//attach the listener
file_fr.addListener(list_obj);
//the event for the browse button
browse_btn.onRelease = function() {
file_fr.browse([{description:"JPEGs", extension:"*.JPG;*.jpg"}]);
};
//the event for the upload button
upload_btn.onRelease = function() {
file_fr.upload("http://www.capaetal.pt/jplanche/upload/upload.php");
};
imagePane.addEventListener("complete", imageDownloaded);
// show image
function imageDownloaded(event:Object):Void {
debug_txt.text += "imageDownload function called";
if (event.total == -1) {
imagePane.contentPath = "error";
}
}
// show uploaded image in scrollPane
function downloadImage(file:Object):Void {
debug_txt.text += "downloadImage";
imagePane.contentPath = "http://localhost/jplanche/upload/files/"+file;
}

Anyone with an idea why is this happening?

thanks

amandeepsiin
01-09-2007, 01:07 PM
First take a look at this...

http://www.checkupdown.com/status/E403.html

cmbarsotti
01-09-2007, 01:07 PM
I remember that happening to me but I'm not remembering why, I'll look into my notes but my first question is have you tried to upload it to a web server or are you just running this locally (through IIS?)?

(I think amandeepsiin and I posted at the same time and I like that answer better then mine.)

Planche
01-09-2007, 02:33 PM
amandeepsiin - I've seen and I canīt imagine why this is still reporting that error.

cmbarsotti - I'm running this on a web server: www.capaetal.pt/jplanche/upload/

thanks.

cmbarsotti
01-09-2007, 02:44 PM
oh, sorry. I saw the localhost and assumed you were running on IIS. I got sidetracked on something but I do remember getting 403s when I first tried this. I'll see what I can find.

amandeepsiin
01-10-2007, 04:15 AM
amandeepsiin - I've seen and I canīt imagine why this is still reporting that error.

cmbarsotti - I'm running this on a web server: www.capaetal.pt/jplanche/upload/

thanks.

See this error happen due to the reason that you dont have access right of that folder. First check the access right for the folder.

Planche
01-10-2007, 10:31 AM
I gave the right to the folder: chmod 777
And still is not working...

Planche
01-10-2007, 11:20 AM
This is the code I have just now and still getting the same 403 error:


System.security.allowDomain("http://www.capaetal.pt/jplanche/upload/");
//import the FileReference Object
import flash.net.FileReference;
//initial settings
upload_btn.enabled = false;
//the FileReference object
var file_fr:FileReference = new FileReference();
//object for listening to for FileReference events
var list_obj:Object = new Object();

list_obj.onSelect = function(file_fr:FileReference) {
debug_txt.text += "onSelect";
upload_btn.enabled = true;
name_txt.text = file_fr.name;
};
list_obj.onOpen = function(file_fr:FileReference) {
imagePane.contentPath = "http://www.capaetal.pt/jplanche/upload/files/" + file_fr.name;
}
//if a user selects cancel
list_obj.onCancel = function(file_fr:FileReference) {
debug_txt.text += "onCancel";
debug_txt.text = "Cancel was selected";
};
//if there is an IO error
list_obj.onIOError = function(file_fr:FileReference) {
debug_txt.text += "onIOError";
debug_txt.text = "IO error with "+fileRef.name;
};
//security error problem
list_obj.onSecurityError = function(file_fr:FileReference, error) {
debug_txt.text += "onSecurityError";
debug_txt.text = "Security error with "+fileRef.name+":"+error;
};
//httpError
list_obj.onHTTPError = function(fileRef:FileReference, error:Number) {
debug_txt.text += "onHTTPError";
debug_txt.text += "HTTP error: with "+fileRef.name+":error #" + error;
};

imagePane.addListener("complete", imageDownloaded);
//attach the listener
file_fr.addListener(list_obj);
//the event for the browse button
browse_btn.onRelease = function() {
file_fr.browse([{description:"JPEGs", extension:"*.JPG;*.jpg"}]);
};
//the event for the upload button
upload_btn.onRelease = function() {
myUpload();
};
//
myUpload = function () {
debug_txt.text = "Uploading: " + file_fr.name + "\n";
file_fr.upload("upload.php");
};


I've done a chmod 777 on the folder "files"

Planche
01-10-2007, 02:54 PM
I also have been doing some local testing, in Apache, and the files do upload to the directory, and then they also download to a specific movie clip. Now comes the strange thing.. I have like 11 jpg's files, and just the ones that start with an "a" (without quotes) do download to the movie clip, the others just don't:


//import the FileReference Object
import flash.net.FileReference;
//initial settings
upload_btn.enabled = false;
//the FileReference object
var file_fr:FileReference = new FileReference();
//object for listening to for FileReference events
var list_obj:Object = new Object();

list_obj.onSelect = function(file_fr:FileReference) {
debug_txt.text += "onSelect";
upload_btn.enabled = true;
name_txt.text = file_fr.name;
};
list_obj.onOpen = function(file_fr:FileReference) {
//imagePane.contentPath = "http://localhost:8888/upload/files/" + file_fr.name;
imageloader.loadMovie("http://localhost:8888/upload/files/" + file_fr.name);
}
//if a user selects cancel
list_obj.onCancel = function(file_fr:FileReference) {
debug_txt.text += "onCancel";
debug_txt.text = "Cancel was selected";
};
//if there is an IO error
list_obj.onIOError = function(file_fr:FileReference) {
debug_txt.text += "onIOError";
debug_txt.text = "IO error with "+fileRef.name;
};
//security error problem
list_obj.onSecurityError = function(file_fr:FileReference, error) {
debug_txt.text += "onSecurityError";
debug_txt.text = "Security error with "+fileRef.name+":"+error;
};
//httpError
list_obj.onHTTPError = function(fileRef:FileReference, error:Number) {
debug_txt.text += "onHTTPError";
debug_txt.text += "HTTP error: with "+fileRef.name+":error #" + error;
};

imagePane.addListener("complete", imageDownloaded);
//attach the listener
file_fr.addListener(list_obj);
//the event for the browse button
browse_btn.onRelease = function() {
file_fr.browse([{description:"JPEGs", extension:"*.JPG;*.jpg"}]);
};
//the event for the upload button
upload_btn.onRelease = function() {
myUpload();
};
//
myUpload = function () {
debug_txt.text = "Uploading: " + file_fr.name + "\n";
file_fr.upload("upload.php");
imageloader.loadMovie("http://localhost:8888/upload/files/" + file_fr.name);
};

cmbarsotti
01-10-2007, 04:20 PM
The test I did last month just automatically opens a dialog box, no interface:

http://cdotspace.com/test/untitled-2.html

The actionscript I used was just lifted from the help files.

Are you able to upload using just the server-sdie script? (Taking Flash out of the equation?)

Actionscript:

import flash.net.FileReferenceList;
import flash.net.FileReference;
var listener:Object = new Object();
listener.onSelect = function(fileRefList:FileReferenceList) {
traceThis("onSelect");
var list:Array = fileRefList.fileList;
var item:FileReference;
for (var i:Number = 0; i < list.length; i++) {
item = list[i];
traceThis("name: " + item.name);
traceThis(item.addListener(this));
if (!item.upload("upload.asp")) {
traceThis( "Upload dialog failed to open.");
}
}
};
listener.onCancel = function():Void {
traceThis("onCancel");
};
listener.onOpen = function(file:FileReference):Void {
traceThis("onOpen: " + file.name);
};
listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
traceThis("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
};
listener.onComplete = function(file:FileReference):Void {
traceThis("onComplete: " + file.name);
};
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
traceThis("onHTTPError: " + file.name + " httpError: " + httpError);
};
listener.onIOError = function(file:FileReference):Void {
traceThis("onIOError: " + file.name);
};
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
traceThis("onSecurityError: " + file.name + " errorString: " + errorString);
};
var fileRef:FileReferenceList = new FileReferenceList();
fileRef.addListener(listener);
fileRef.browse();
function traceThis(str) {
txt.text += str + "\n";
}


ASP:

<%
Set Upload = Server.CreateObject("Persits.Upload")

'Uncomment the next line if you need to set user access to domain with username and password
'Upload.LogonUser "mydomain", "Administrator", "xxxxxxxxx"

'Set code page
Upload.CodePage = 65001

'Set to not overwrite files (True/False)
Upload.OverwriteFiles = False

' Limit file size (bytes)
Upload.SetMaxSize 5000000, True

' Intercept all exceptions to display user-friendly error
On Error Resume Next

'Set the path to the folder on server to write the files to
strPath = "E:\WWW\cdotspace.com\wwwroot\test\"

'Create directory if it does not exist
Upload.CreateDirectory strPath, True

' Perform upload
Upload.Save strPath

strFilePath = Upload.Files("selectedFile").Path

' 8 is the number of "File too large" exception
If Err.Number = 8 Then
'File is too large do nothing
Else
If Err = 0 Then
Select Case Ucase(right(strFilePath,4))
Case ".JPG", ".GIF",".PNG"
'Acceptable file to be uploaded
Case Else
'Delete file
Upload.Files("file1").Delete
End Select
End If
End If
%>

Planche
01-10-2007, 04:41 PM
Isn't this just the same thing... You have to use a server side script to upload the files, that's what I'm doing.

cmbarsotti
01-10-2007, 05:01 PM
yes, it is. I'm sorry, I just posted it as confirmation that what you had should work.

Sorry, I just woke up and had three very long phone calls before I had coffee.