Is there a way to access the network share folder with the provided credentials in flutter?
I've tried using the Uri's constructor to pass in the credentials but I'm met with an error saying that they are invalid.
final uri = Uri(
scheme: "file",
host: 'ipaddress',
path: 'filepath',
userInfo: "username:password",
);
final file = File.fromUri(uri);
//Error thrown when trying to read file
Related
While calling an API (not mine, a 3rd party server), using the HTTP package, I get the following error:
Error: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current
I get this only when running locally on web, not with the iOS emulator (works just fine there).
This didn't help me
Here's the code:
try {
response = await _httpClient.get(
Uri(
scheme: 'http',
host: host,
path: path,
),
headers: {
"Access-Control-Allow-Origin": "*",
},
);
}
well, changed scheme: 'http' to scheme: 'https' and it works...
Don't know why it works on mobile and not on web
I am new creating Flutter web projects, and I have found the first issue when trying to make http connections to files hosted on the same server where the Flutter web build is deployed.
This is the code:
Future<User> obtenerUsuario() async {
setState(() {
isLoading = true;
});
var url = "https://.../login.php";
final response = await http.post(url, body: {
"email": controlUsuario.text,
"password": controlContrasena.text
});
print("respuesta :"+response.body);
And this is the error message from browser console:
Access to XMLHttpRequest at 'https://.../login.php' from origin 'http://...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The project is hosted on a AWS Ubuntu instance.
Add the following code to your server .htaccess
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
I am trying uploading a image using below code.
String _urlsegment =
Explika.producaoFlag ? 'https://www.remoteserver.pt' : 'http://10.0.2.2';
var stream = http.ByteStream(
DelegatingStream.typed(compressedFileImage.openRead()));
var length = await compressedFileImage.length();
var uri = Uri.parse('$_urlsegment/explika/api/upload');
var request = http.MultipartRequest("POST", uri);
var multipartFile = http.MultipartFile('fotoaluno', stream, length,
filename: '${Explika.getAluno().id}.jpg');
request.files.add(multipartFile);
Everything work fine using localhost. When i try send image to remote server nothing happens.
The end point is ok: i tested it using postman and all worked well.
Summing up:
uploading using APP to LOCAL server - OK
uploading to LOCAL server using POSTMAN - OK
uploading using APP to REMOTE server - Fail (No error occurs but file does not reach server)
uploading to REMOTE server using POSTMAN - OK
Any ideas on what is going on? Do I need to enter any special permissions in the app manifest?
Flutter sends the images with mime type 'application / octet-stream'. The server was waiting for files with mime type 'image / jpeg', so it automatically rejected the file.
I have developed a REST Web service to get resources, I am able to access it through Java/Spring Template and even the xml response is coming if I type the URI on browser.
But when I invoke the same URI using XMLHttpRequest in Java script I am getting the below error.
"XMLHttpRequest cannot load URI(actual uri with server name ..etc) . Origin file:// is not allowed by Access-Control-Allow-Origin."
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101.
My JS code is as below.
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://localhost:8080/rest/apps", false );
xmlHttp.send( null );
Please let me know what would be the problem and help me to resolve this.
Regards,
Sreedhar
here Origin is the local file system, that you're loading the HTML page, that load call via a file:/// . the request is from the same origin. If you're trying to load from somewhere else then you will not get the Error.
Check For this answer
I have a problem downloading particular file types by WebClient. So there are no problems with usual types - mp3, doc and others, but when I rename file extension to config it returns me:
InnerException = {System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
when I'm trying to access this file in browser (http://localhost:3182/Silverlight.config) - it's a usual xml file within - server returns me following error page:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.config' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /Silverlight.config
So I suppose this hapens because of some server configuration, which blocks files of unknown type.
downloading code is simple:
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(new Uri("../Silverlight.config", UriKind.RelativeOrAbsolute));
completted eventhandler omitted for simplicity.
I'm not sure this is possible.
The .config extension is handled by the ASP.NET engine, for security reasons (sensitive data like connection strings need to be kept safe and hidden from unauthorized viewers).
This means that visitors cannot view your web.config file's content by simply entering "www.example.com/web.config" into their browser's adress bar.
EDIT : actually you can but I don't recommand it. If you really need to do it, you have to remove the mapping between the .config extension and ASP.NET ISAPI filter in IIS.