Reputation: 93
I am developing a xamarin forms based cross platform mobile application, I am new to this technology, hontestly.
I am using this plgin to to upload files to the server
https://github.com/CrossGeeks/FileUploaderPlugin
but it does not seems to work at all, at server I am not getting any POST value at all.
I have tried xamarin community forum, but it didn't help too.
I suppose there could be problem like this
Path issue but I have printed path on screen and its correct
URL being hit I have verfied that as well by performing some other action on server, URL is being hit too, it performed the other action but did not get any POST
Here is my C# code
string url = "http://example.com/file_upload.php";
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("fileName", "Kamran");
// filePath returns correct value I have verified that
FilePathItem fpi = new FilePathItem("file", filePath);
Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("Content-Type", "multipart/form-data");
await CrossFileUploader.Current.UploadFileAsync(url,fpi,header, parameters, null);
Here is my Server side code
<?php
$n = basename($_FILES["file"]["name"]);
$target_dir = "uploads/";
$target_file = $target_dir . $n;
$senderName = $_POST['fileName'];
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file. : " .$n.", sender: " . $senderName;
}
?>
I do not see any POSTED vars, I trield saving all posted vars as JSON string as well, but nothing is coming.
Upvotes: 2
Views: 889
Reputation: 93
I know it might seems stupid, but I am just posting the answer so, someone might not forget this simple thing and add it into checklist of while debugging.
The simple issue was http and https, web server URL must be with "https" not http, maybe there are ways to work with http too, but in situation it was not allowing without "https" there was nothing wrong with rest of the code at all.
Upvotes: 2