Adobe Air upload progress without FileReference - apache-flex

I'm deploying a small application with Adobe Air. My application will do batch upload from filepath which stored in a text file.
For example, in a text file name "list.txt", there is a string "C:\myfiles\IMG_0001.JPG". Now I want to upload this image file, keep tracking of upload progress :-<
I want to use FileReference to get the upload progress, but I don't know how to import from file's path. I also wonder how to use FileReference to upload this file without prompting a dialog for user to select file.
Thank you so much :)

Try the following. I have done a file upload without dialog box using following code.
var uploadURLs:URLRequest = new URLRequest("Your upload URL Here");
var params:URLVariables=new URLVariables();
params.title = "Hello";//URL Parameters if there is any
uploadURLs.data = params;
uploadURLs.method=URLRequestMethod.POST;
file = new File("Path to File");
file.addEventListener(ProgressEvent.PROGRESS , updateProgress);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, doneUpload);
file.addEventListener(IOErrorEvent.IO_ERROR,fileError);
file.upload(uploadURLs);
Hope this helps

Related

GUI made using JavaFx that uses File Input/Outstream - Can it be exported as JAR and open .txt file?

I am trying to export a GUI (Student Grade Manager App) I created in eclipse as a JAR file and run it on my desktop. Nothing happens when I double click it (though it does successfully export) at the moment. Here's an screenshot:
GUI Screenshot - Click here
I'm assuming the main issue here is that in my GUI, I am using the File Input stream in the CourseSectionApp.java file (Where the main method is located). It reads a .txt file called "StudentMarks.txt" and that's where it gets all its student data from.:
BufferedReader aFile = new BufferedReader ( new FileReader("Marks.txt"));
model = CourseSection.loadFrom(aFile);
Is there anyway to get this to work? Can I have the .txt file just export with the JAR file so it loads together? OR is there a way to put a sub-window, like modern applications have where the user can go to File->New-> and say, "load from file", and then be allowed to navigate to the .txt file on his computer?
My main goal is to be able to email this to friends and have them use it, but I googled around and only found a few people having similiar issues with not-so-clear answers. And if the JAR file cannot do this, what can? Will making it a .exe change anything?
Screenshot of Marks.txt file
I tried to make this question as legible as possible and if there is any other information I can provide you guys, please let know.
If you don't need to write to the file, including the file as resource in the jar would be your best option. This way you can always be sure the file is available via jar entry name. E.g.
try (InputStream is = getClass().getResourceAsStream("/data/Marks.txt");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr)){
model = CourseSection.loadFrom(br);
}
If you also need to write to the file, you can use FileChooser to open a dialog for choosing a file:
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Marks File");
fileChooser.getExtensionFilters().add(new ExtensionFilter("Text Files", "*.txt"));
File file = fileChooser.showOpenDialog(null); // you could also pass a owner window here
if (file != null) {
// TODO: handle completed file selection by user
}
The issue described in the comments indicates that there is a problem with the classpath though. You need to make sure all required classes are available when the application is run...

TxTextControl Load a Image into document Dotnet

I am new to TXTextControl. I am currently using TXTextControl 24 version.
I need to upload an image from local system (Client system) into the document.
I have written the JS for uploading the file through .
The JS makes a call to backend service which gets the file, Add it to a new RTF file and respond back to JS. The RTF file is then loaded to the Selection.Load of TextControl.
Code: add image to RTF
TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl();
tx.Create();
tx.Images.Add(myImage, tx.InputPosition.Page, new Point(100, 100), TXTextControl.ImageInsertionMode.FixedOnPage);
string sHTML;
tx.Save(out sHTML, TXTextControl.StringStreamType.RichTextFormat);
The server responds back with with message "The Module for displaying image is obsolete. (01-0803)"
How can I add the Image into the TXTextControl Document ?

Upload mutliple files using FileUpload asp.net

I have been struggling with this issue for some time now.
I have a web interface where I create projects, with this you should be able to upload multiple documents to the server, which is attached to the project they belong to.
So far I made it work with only uploading one file at a time.
My idea was maybe to add the "file" objects in an arralylist and then bind it to a gridview and then upload it to the server?
I know this sound a bit confusing, but I'm confused also!
This is how my method look like when I upload a single file to the server and also save the file's ID, name and context in the database:
File file = new File();
Projects_Overview po = new Projects_Overview();
po.Name = TextBoxName.Text;
po.Time = time;
po.Owner = TextBoxOwner.Text;
po.Responsibility = TextBoxResp.Text;
po.Created = datecreate;
po.StartDate = datestart;
po.FinishDate = datefinish;
po.ETC = dateETC;
po.Description = TextBoxDesc.Text;
po.Comments = TextBoxComments.Text;
po.Remember = TextBoxRemember.Text;
ie.Projects_Overview.AddObject(po);
ie.SaveChanges();
if (uploadFile.HasFile)
{
string filepath = uploadFile.PostedFile.FileName;
string fileName = Path.GetFileName(filepath);
file.Context = Path.GetFileNameWithoutExtension(uploadFile.PostedFile.FileName);
file.Extension = Path.GetExtension(uploadFile.PostedFile.FileName).Replace(".", "").Substring(0, 4);
file.FileName = Guid.NewGuid();
string fileSavePath = Server.MapPath("") + "\\Wordfiles\\" + Convert.ToString(file.FileName) + ".upl";
uploadFile.PostedFile.SaveAs(fileSavePath);
file.ProjectID = po.ID;
ie.File.AddObject(file);
ie.SaveChanges();
Can someone tell me how to "attach" multiple files and then save them in the folder along with the other data as I posted above?
Cheers
I believe that HTML 5 has the built-in capability to handle multi-file uploads (where HTML4 does not), but I have not worked with HTML5 yet. With HTML4, you must use an external control (typically either javascript or flash), as there is no built-in mechanism to allow multi-file uploads.
I did write a multi file upload page that works with HTML4 or HTML5 utilizing PLupload (an external control) to perform the file picking. I had to find a generic file handler to interface the control to the .aspx upload page. I think that I found that here.
It took a couple hours to implement, but it's worked great.

How can I convert a PDF file to an image?

I'm giving users the ability to upload an image to my Air app, then displaying this image in an image control. But I need to allow for PDF uploading in the same manner, so I need to convert the PDF to an image. I only care about the first page of the PDF they upload for now.
What I'm doing is:
1) User browses for a file with the file reference control
2) User chooses the image or PDF to upload
3) I encode said image to base64 and store it
4) I then load from that base64 with something like:
public function decodeImage(b64String:String):void{
var decoder:Base64Decoder = new Base64Decoder();
decoder.decode(b64String);
var imgLoader:Loader = new Loader();
imgLoader.loadBytes(decoder.toByteArray());
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,decodedImageLoaded);
}
private function decodedImageLoaded(event:Event):void{
var imgLoader:Loader = (event.target as LoaderInfo).loader;
var bmp:Bitmap = Bitmap(imgLoader.content);
imgLoader.removeEventListener(Event.COMPLETE, decodedImageLoaded);
var img:Image = new Image();
img.source = bmp;
this.addChild(img);
}
This method is working great for .gif, .jpg, and .png. At some point in my process, probably the initial upload I need to convert the first page of a PDF to a png so that I can use the rest of this process.
I welcome any ideas with the sole requirement being that it has to be a part of the Air app, I can't use something like ImageMagick that runs on a server, but I could use a component that I can compile in to the finished product.
I believe AlivePDF for Flash now has capabilities to read a PDF file. You might try PurePDF, as well. You could potentially use ones of these to get that desired page and convert it to an image.
Have you seen swftools? It has the ability to convert a PDF to a SWF, PNG, JPG, etc...

Saving a file in Flex Air

I'm trying to copy my SQLite file that is used in my Air app to user's selected directory using
var fileSaveDest:FileReference = new FileReference();
fileSaveDest.save(dbWorkedFile,'Inventory.DB');
dbWorkedFile is a File
dbWorkedFile = File.documentsDirectory.resolvePath("Inventory.db");
I tried this but the saved file isn't a valid SQLite file.
Also, I was wondering whether it's possible to embed SQLite to Air? If so how can I import and export the database?
Many thanks
In the end I couldn't get FileReference.save() to work so I go with the regular File's browseForSave()
dbWorkedFile.addEventListener(Event.SELECT, savingDatabase);
dbWorkedFile.browseForSave('Specify save location');
private function savingDatabase(event:Event):void
{
var selectedFile:File = File(event.target);
//To ensure the file is still loaded
dbWorkedFile = File.applicationStorageDirectory.resolvePath("Inventory.db");
dbWorkedFile.copyTo(selectedFile, true);
}
There is a short article describing how to include some SQLLite files in an AIR application on Adobe website (cookbooks section).

Resources