Hi,
I am able to download jpg, png, pdf and mp4 files through REST API but I get HTTP error 400 while downloading an xml file.
I am using ActionScript in Flash Professional CC2015.
Sometimes I am able to download, most of the times not.
Below is code I am using:
public static var headers:Array = [
new URLRequestHeader(‘application-id’, ‘my App Id’),
new URLRequestHeader(‘secret-key’, ‘my App Secret Key’),
new URLRequestHeader(‘Content-key’, ‘application/json’),
new URLRequestHeader(‘application-type’, ‘REST’)
]
public static function FileDownload(location: String, filename: String, success: Function, progress: Function = null, error: Function = null): URLLoader {
var url: String
if(location != ‘’){
url = filesSecureUrl + location + ‘/’ + filename;
}else{
url = filesSecureUrl + filename;
}
trace(“downloading url:”, url)
var req: URLRequest = new URLRequest(url)
req.requestHeaders = Backendless.headers
req.requestHeaders.push(new URLRequestHeader('user-token', BackendUser.user_token))
req.method = URLRequestMethod.GET
var loader: URLLoader = new URLLoader();
var a:Array = filename.split('.')
var ext:String = String(a[a.length-1]).toLowerCase()
if(ext == 'txt' || ext == 'xml'){
trace('data type is text or xml')
loader.dataFormat = URLLoaderDataFormat.TEXT
}else{
trace('data type is binary')
loader.dataFormat = URLLoaderDataFormat.BINARY
}
var loaded_fn: Function = function (e: Event): void {
loader.removeEventListener(Event.COMPLETE, loaded_fn)
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError_fn)
loader.removeEventListener(ProgressEvent.PROGRESS, progress_fn)
success(loader.data)
}
var progress_fn: Function = function (e: ProgressEvent): void {
var perc:int = int((e.bytesLoaded/e.bytesTotal) * 100)
progress(perc, e.bytesLoaded*0.001, e.bytesTotal*0.001)
}
var onIOError_fn: Function = function (e: IOErrorEvent): void {
loader.removeEventListener(Event.COMPLETE, loaded_fn)
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError_fn)
loader.removeEventListener(ProgressEvent.PROGRESS, progress_fn)
if (error != null) {
error(e.text)
}
trace("Error downloading file.", e.text)
}
if(error != null){
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError_fn)
}
if(progress != null){
loader.addEventListener(ProgressEvent.PROGRESS, progress_fn)
}
loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, function(e:HTTPStatusEvent):void{
trace('HTTP Status while downloading file:', e.status)
})
loader.addEventListener(Event.COMPLETE, loaded_fn)
loader.load(req)
return loader
}
Please let me know what could have gone wrong.
Or let me know other simpler way to edit an already uploaded xml file.
Thanks,
Tushar