i am having an issue everytime i try to upload an image from a flex mobile application to an IIS directory and this directory is configerd to be web application
i get an HTTP error 405 'method not allowed'
hence i dont use any script from the server side and i dont want to use any ..
and the code for the upload button is
protected function getImage(event:Event):void
{
var image:Bitmap = Bitmap(event.target.content);
bitmapData = image.bitmapData;
byte = jpgEncoder.encode(bitmapData); // bytearray
uploadrequest = new URLRequest("http://localhost/ProblmeImages/");
var header:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
uploadrequest.requestHeaders.push(header);
uploadrequest.method = URLRequestMethod.PUT;
uploadrequest.data = byte;
urlloader1.dataFormat = URLLoaderDataFormat.BINARY;
urlloader1.addEventListener(Event.COMPLETE,uploaded);
urlloader1.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS,displayerror);
urlloader1.load(uploadrequest);
}
protected function uploaded(event:Event):void
{
PopUpManager.removePopUp(Alert);
errormsg = "Done!";
var str:String = urlloader1.data;
PopUpManager.addPopUp(Alert,this,true);
PopUpManager.centerPopUp(Alert);
}
protected function displayerror(event:Event):void
{
errormsg = httpresponsemsg;
PopUpManager.addPopUp(Alert,this,true);
PopUpManager.centerPopUp(Alert);
}
Related
I've got an app that, since 5 years now, that displays an offline map by reading from a folder embed in it ("assets").
Since Android 11, it's impossible to read from ApplicationStorage (Error #3001: File or directory access denied), so I'm trying to copy the folder from applicationStorage to "Documents".
What I did :
source = File.applicationDirectory.resolvePath("assets/maps");
destination = File.documentsDirectory.resolvePath("Documents/www");
source.addEventListener(Event.COMPLETE, onMapCopyComplete);
source.copyToAsync(destination, false);
function onMapCopyComplete(e: Event): void {
source.removeEventListener(Event.COMPLETE, onMapCopyComplete);
log("onMapCopyComplete()");
}
I've got a return onMapCopyComplete() but when I'm looking in InternalStorage/Documents of my phone I've got the folders but all are empty... None of the files were copy..
PrintScreen computer vs phone
To read the files, here's what I'm doing :
function startMapsView()
{
var indexFile:File = File.applicationStorageDirectory.resolvePath("www/index.html");
if (!indexFile.exists)
{
log("startMapsView() Index file not found, Please check www/index.html");
return;
}
// Create StageWebView
stageWebView = new StageWebView(isMobile); // Set to TRUE for System's NativeWebView, FALSE is for AIR's WebView
stageWebView.stage = stage;
stageWebView.viewPort = new Rectangle(0, iOSStatusBarHeight + headerBarHeight, deviceStageSize.width, deviceStageSize.height - (iOSStatusBarHeight + headerBarHeight + footerBarHeight));
stageWebView.addEventListener(flash.events.Event.COMPLETE, onStageWebViewLoaded);
stageWebView.addEventListener(flash.events.ErrorEvent.ERROR, onStageWebViewError);
stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, onStageWebViewLocationChanging);
// Load Map URL
stageWebView.loadURL(mapsURL);
}
And mapsURL is define by :
function setMapsURL(doNotEnableButtons: Boolean = false): void {
var indexFile: File = File.documentsDirectory.resolvePath("Documents/www/index.html");
trace("indexFile url is = "+indexFile.url);
if (!indexFile.exists) {
log("setMapsURL() Index file not found, Please check www/index.html");
return;
}
var assetsDir: File;
if (!useOnlineMaps) {
assetsDir = new File(destination.resolvePath("index.html").nativePath);
} else {
assetsDir = new File(destination.resolvePath("onlineMaps.html").nativePath);
mySavedData.data.onlineMapChoosen = false;
}
mapsURL = assetsDir.url;
log("setMapsURL() " + mapsURL);
if (!doNotEnableButtons) enableMapButtons();
}
I am trying to blur an image in my new Windows Phone Runtime C# app (WPRT)
I used WriteableBitmapEx NuGet and this code to make my image blured but can't see any changes in my picture . what's going wrong guys ?
public TestXaml()
{
this.InitializeComponent();
....
test();
}
async void test()
{
var ImgFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/TestBG.jpg"));
var wb = new WriteableBitmap(100,100);
using (var strm = await ImgFile.OpenReadAsync())
{
wb = await wb.FromStream(strm);
}
var wb3 = WriteableBitmapExtensions.Convolute(wb, WriteableBitmapExtensions.KernelGaussianBlur5x5);
ImageBrush ib = new ImageBrush();
ib.ImageSource = wb3;
PageBackground.Background = ib;
}
also I tried WriteableBitmapExtensions.KernelGaussianBlur3x3 but still no change
Below code is used to read a file in the disk and upload as 1MB chunks to a php server via adobe AIR application. It iterates the do/while loop till the end of the file and uploading part is handled by function getConnection. The servers returns an XML as the response. With the eventListeners currently it goes to function onRequestComplete when it receives the response. Because of that issue current code exits the loop when it receives the response from the server. Is there any way that I can get the response of the request send by the function getConnection when it calling inside function startUpload ? also how can I define the request timeout for this single requests?
private function startUpload():void {
var localFilePath:String =localFilesToUpload[currentUploadedVideoIndex].file.nativePath;
var filePathArray = localFilePath.split("/");
var uploadedFile:File = new File(localFilePath);
var fileSize:Number = uploadedFile.size;
var fileName:String = filePathArray[filePathArray.length-1];
var fileId:String = "10";
var index:Number=0;
var chunkSize:Number=1024*1204;
var size:Number=chunkSize;
var serverPath:String = "http://myurl/rests";
//encode username and password
var userName:String="myusername";
var password:String="mypassword";
var encoder:Base64Encoder = new Base64Encoder();
encoder.insertNewLines=false;
encoder.encode(userName+":"+password);
var urlLoader:URLLoader=new URLLoader();
urlLoader.dataFormat=URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE,onRequestComplete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,onResponceFail);
var urlRequest:URLRequest = new URLRequest(serverPath);
urlRequest.method=URLRequestMethod.POST;
do{
//if this is true file must be uploaded as a chunk
if(fileSize>chunkSize){
if((index+size)>fileSize){ // if true this is the final chunk of the file.
size = fileSize-index; // take the remaining size of the file
}
}else{
size = fileSize; //this file can be uploaded directly
}
//read the bytes from the file in the specified location
var buff:ByteArray = new ByteArray();
var uploadedFileStream:FileStream = new FileStream();
uploadedFileStream.open(uploadedFile,FileMode.READ);
uploadedFileStream.readBytes(buff);
uploadedFileStream.close();
urlRequest.data=buff;
//add the http headers to the file part and send
this.getConnection(urlRequest, urlLoader,encoder.toString(),fileSize,index,chunkSize,fileName,fileId,buff);
}while(index<fileSize)
}
}
private function getConnection(urlRequest:URLRequest, urlLoader:URLLoader ,authString:String, fileSize:Number, index:Number, chunkSize:Number, fileName:String, fileId:String, requestBody:ByteArray):void{
//creates the relevent HTTP heaaders and assigned to parameters
try{
urlRequest.requestHeaders = parameters;
urlLoader.load(urlRequest);
}catch(error:Error){
Alert.show(error.message);
}
}
private function onRequestComplete(event:Event):String{
var loader:URLLoader = URLLoader(event.target);
Alert.show(loader.data,"Result");
}
private function onResponceFail(event:FaultEvent):void{
Alert.show(event.message.toString(),"Fault");
}
In order to achieve this, you should check if operation is finished in onRequestComplete instead:
Pseudo code just to get you going:
function startUpload()
{
// prepare big file
...
// then start the uploading
sendNextChunk();
}
function sendNextChunk()
{
// grab the next chunk
...
// and send it
getConnection(...);
}
function onRequestComplete()
{
// is there more chunks ?
if (...more chunks?)
sendNextChunk();
else
trace("All chunks uploaded");
}
Hope that helps,
Adnan
I'm trying to access a webservice with an SSL connection from an AIR application, I can access the webservice and retrieve the data without SSL, but when I try and access it through it I end up getting the 2032 Stream Error. As if what I was attempting to access wasn't available (which in fact it is, since I can easilly access it through my browsers).
I am doing the following:
private var server:String = "";
private var contentType:String = "";
private var method:String = "";
private var connector:connectionTest = null;
private var serverURL:URLLoader = new URLLoader();
public function Connector(a2:String, a3:String, mainClass:connectionTest)
{
server = "url";
contentType = a2;
method = a3;
connector = mainClass;
}
public function callService(callback:String, request:Object):void{
var url:URLRequest = new URLRequest(server);
var encoder2:JSONEncoder = new JSONEncoder(request);
var requestedString:String = "0" + encoder2.getString();
url.contentType = contentType;
url.method = method;
url.data = "callback=" + callback;
url.data +="&request=" + encodeURI(requestedString);
url.authenticate = true;
serverURL.addEventListener(IOErrorEvent.IO_ERROR, treatIO);
serverURL.addEventListener(Event.COMPLETE, loadData);
try{
serverURL.load(url);
}catch(e:ArgumentError){trace("ArgError: " + e.message);}
catch(e:SecurityError){trace("SecError: " + e.message);}
}
private function treatIO(e:IOErrorEvent):void{
trace(e.text);
}
private function loadData(e:Event):void{
trace("loaded");
connector.htmlObject.htmlText = serverURL.data as String;
trace(serverURL.data);
}
explanation: mainClass is an mxml file with just a button and an html object in it.
Note: I have done the recommended thing of adding to Flex the certificate.
Anyone out there that can assist with this?
Edit:
I also tried with the URLStream class and it still doesn't handle it, seems like I can't actually get a connection to the server...
Even tho I do connect to it in a browser or even SoapUI
We faced the same problem on some machines (Win7 64bit), unfortunatelly still not solved. Maybe this is relevant:
http://forums.adobe.com/message/4028647#4028647
When I ran into this problem it was caused by my hosting company introducing an inconsistency between the name in the SSL certificate and the URL I was calling, when I replaced https://www.example.com/ with https://example.com/ everything started to work again.
I am trying to upload a photo from an Adobe AIR application to yfrog's api, http://code.google.com/p/imageshackapi/wiki/YFROGuploadAndPost. I have the following code:
public function upload(file:File, msg:String, username:String, password:String):void {
var vars:URLVariables = new URLVariables();
vars["username"] = username;
vars["password"] = password;
vars["public"] = "yes";
vars["key"] = API_KEY; //API_KEY is a constant string that holds my developer key
vars["message"] = msg;
var request:URLRequest = new URLRequest("http://yfrog.com/api/uploadAndPost");
request.method = URLRequestMethod.POST;
request.contentType = "multipart/form-data";
request.data = vars;
file.upload(request, "media");
}
When I run this code, yfrog returns 404 status. This seems to only happen if I do a media file upload with the api. If I use a "url" upload to the same api url - everything works. Has anyone else gotten a "media" file upload to work? If so, how would you change the code?
Looks like that API has been replaced as of today with the OAuth Echo method
http://code.google.com/p/imageshackapi/wiki/TwitterAuthentication