read file from ftp server - android

What is the best way to read the content of a FTP file from within a HTML5-App?
I have tried:
$.ajax
({
async: false,
url: 'ftp://ftp.XXX.de/Sonstiges/XXX.json',
dataType: 'json',
timeout:30000
})
.done(function (data)
{
//...
})
.fail(function (jqXHR, textStatus)
{
//...
}
but I always get into fail, probably because of a cross-domain security error.

Hmmm... There is one thing you need to take into account: ajax request could only send HTTP request, please refer to Does jQuery support ftp request?

Related

Expo android network request failed

I want to post a wav file(in blob) to my server.
I've tested my server using postman, and it works fine.
I also creat a react-app(web) and post the wav using the same logic below successfully.
const formData = new FormData();
formData.append('file', blob, 'test');
let requestOptions = {
method: 'POST',
body: formData,
mode:'no-cors',
};
// not localhost
fetch('http://xx.xx.xx.xx', requestOptions)
.then(response => response.text())
.then(result => {
console.log(result)
})
.catch(error => console.log('error', error));
However I cannot even send the request out on my phone(Only got [TypeError: Network request failed] and my server didn't receive any request.)
I've been looking online and still not fix this issue. Please help.
It is not about the Blob, but more about the error you go.
So not sure if it can help...
I found out that I needed to put the Mime Type to match the file to upload.
formData.append('file', {
uri : "file://...",
name : "filename.mp4",
type: "video/mp4",
});

React-Native: Downloading and uploading files from android webview

I am using the React-Native webview bridge module because I need its functions and now I am trying to make work the downloading and uploading files. For downloading I was sending a message with the url of the file and then using the Linking package to download in browser, unfortunately I was getting that the download is unsuccessful. Is there a way how I can manage both to work on this module?
I recently had to face the same problem for Android (although only for file uploads). You can see my implementation here: https://github.com/martinarroyo/react-native-webview-file-upload/
Maybe if you extend that code to include something like this you can include file downloading.
fetch(
_apiRoot+url+'?_format=json&access_token='+this.getAccessToken(),
{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body:JSON.stringify(data)
}).then((response) => response.json())
.then((response) => {
success(response.data);
})
.catch((errorData) => {
error(errorData);
});
//Where data is an object like
let data = {
images:[responseDataFromImagePicker.data,responseDataFromImagePicker.data]
}
//the picker returns the image encoded in base64

Local web service call in Cordova fails with result ERR_FILE_NOT_FOUND

I am using ASP.Net and building an android app using Cordova 5.1.1. I have created the web service (services.asmx) which has a method appStatus and I am calling the same in index.html page. This works perfectly when I run or publish in my laptop. But once I build and run, I get the file not found error with status 0.
Ajax Call
var request = $.ajax({
url: "services.asmx/appStatus",
method: "POST",
data: {},
dataType: "json",
contentType: "application/json; charset=utf-8",
success: ajaxSigninSuccess,
error: ajaxSigninError
});
function ajaxSigninSuccess(response) {
alert(response.d);
}
function ajaxSigninError(response) {
alert(response.status + " " + response.statusText);
}
Following is the response text
onabort: null
onerror: null
onload: null
onloadend: null
onloadstart: null
onprogress: null
onreadystatechange: null
ontimeout: null
readyState: 4
response: ""
responseText: ""
responseType: ""
responseURL: ""
responseXML: null
status: 0
statusText: ""
timeout: 0
Error
GET file:///android_asset/www/services.asmx/appStatus net::ERR_FILE_NOT_FOUND
Please help, thanks in advance.
You have problem about server + client side.
I call server is where your service ASP.Net ("services.asmx") deploy.
Client is your mobile app in device.
1. When your server + client in your computer.
Ex: url service: "http://localhost:8080/services.asmx" then when you call ajax by url 'services.asmx/appStatus' then it will get path of html file(include ajax code) and prepend to url. If html file is "http://localhost:8080/index.html" then url call by ajax will be: "http://localhost:8080/services.asmx/appStatus". I think it working with you.
2. When server deploy in you computer and client running in device (emulator).
Ip address of your computer and emulator in your computer is different.
Your app start with index.html file: "file:///android_asset/www/index.html" and so that url call by ajax will be: "file:///android_asset/www/services.asmx/appStatus" not found any service or file at url.
3. Solutions: call ajax by full url: "http://domain.com/services.asmx/appStatus" or if your server deploy in local then "http://ipaddress:port/services.asmx/appStatus".

ajax xhr.getResponseHeader("user header") is not working for Android native browser

I am trying to make an AJAX call to a servlet. In the servlet I am setting headers. But the header is not displayed back from the response in the Android native browser. I am not able to read the header. In other browsers it is working fine.
javascript code:
$.ajax({
type: 'GET',
url: url,
cache : false,
async: false,
success: function(data, status, xhr) {
code = xhr.getResponseHeader('X-code');
}
});
I am taking care or CORS issues.
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Request-Method", "*");
response.addHeader("Access-Control-Allow-Headers", "X-code");
response.addHeader("Access-Control-Expose-Headers", "X-code");
Things are working fine for other mobile/web browser, but not working for Android native browser.
Need assistance.
Thanks in advance.

Phonegap - ajax request doesn't work

Have tried for hours to create an simple rss reader with phonegap but it doesn't seems to work. Have tried to set access to: <access origin="*"/> but that does not work.
Here is the code I use to get the rss feed:
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent("http://array.se/feed/"),
dataType: 'json',
success: function(data) {
console.log(data.responseData.feed);
$.each(data.responseData.feed.entries, function(key, value){
var thehtml = '<li>'+value.title+'</li>';
$("#factsfeed").append(thehtml);
});
}
});
The code works in the browser but when I try it out on my Android it does not.
Try setting the dataType to 'jsonp'
Also, "document.location.protocol" might not work as the protocol in PhoneGap is file://, you can probably just remove that and append http to the string after it.

Categories

Resources