I have to send files through my API made in php, via Postman everything works, but from kodular when I do the “.Post File” with the Web component it gives me an error: “Unable to post or put the file” / storage / emulated /0/Android/data/io.makeroid.companion/files/Pictures/kodular_1643300962700.jpg “with the specified URL etc etc.”
The URL is correct, from php I get all the $ _GET variables correctly but the $ _FILES array remains empty, I don’t know what to do anymore, I tried everything, I am attaching the piece of blocks that does the sending, help
Maybe this will help You
And
Why do you have a GET block? You are POSTing a file.
at this point I don’t understand if the Web .Post File needs the relative path or the absolute path
because I have to pass data to the API that the first is needed for authentication, the second indicates the id to be connected in the database, they are two simple data that I have to pass, then from php I take them with the $ _GET
First try to upload one file instead of using for each number block(Multiple files)… if it is successful then instead of using this method just try to use clock component, there by if one file uploaded then second file will try to upload.
You should actually use the Web.GotText event to call the next file to upload…
Complementing the suggestions above, a file-by-file example.
I have a problem with the Post File not with the download of files, I created a test app, but the error I see is “Error 404 File Not Found” I also tried with the Image component and to load a simple image into kodular and even in that case I am returned File Not Found, what is the path of the file to pass to Post File? I can’t figure out if it’s the component that can’t find the file to send
I know that. I thought you would understand the example I posted…
Above you got suggestions to do 1 to 1 and use the Web.Got event.
So , I suggested that you look at that example for you to adapt to yours .
So the suggestions were:
1- check the file location ( POST 2)
2- use web.got ( POST 8 )
Have you checked the contents of your image list?
After take picture, did you, outside of your app, using a file manager, check the folder where the photos are?
And Read
Maybe this will help You
You should be setting headers for this. Read the api documentation, or link to it so we can see how it works. It is not the correct method to try to send a POST “and” a GET request, they are two different and unlinked activities.
I also tried to insert the correct header, the problem remains, no files are passed, but it seems that it has never happened that someone with kodular has to send photos taken with the camera component via the web, it seems that I am the first to do it
Simply your server end - php for testing purposes, if you can get that working, then you can develop things on from there.
Have you checked where the photos are before trying to send them?
I tried this small and simple example, the result is always the same “File Not Found”, could you show me how I can fix this simple block to send the photo taken via Camera to the Web by Post File function?
It doesn’t help that you do not show your url elements (you can hide the address)
You do not show your php file…
Not sure why you are needing to remove brackets from your image path ?
Is your image path readable ?
What is your responseContent ?
Again ,
Have You checked ?
One question : can it be by ftp ?
maybe this piece of blocks will do…
and …
Send it…
use server side code in php
<?php
// Retrieve the request body
$requestBody = file_get_contents('php://input');
// Check if there is content in the request body
if (!empty($requestBody)) {
// Create a file info resource
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// Get the MIME type of the file
$mimeType = finfo_buffer($finfo, $requestBody);
// Map MIME types to file extensions
$mimeToExtension = array(
'image/jpeg' => 'jpeg',
'image/png' => 'png',
'image/gif' => 'gif',
// Add more MIME types and extensions as needed
);
// Get the file extension based on the MIME type
$fileExtension = isset($mimeToExtension[$mimeType]) ? $mimeToExtension[$mimeType] : 'unknown';
// Close the file info resource
finfo_close($finfo);
// Generate a unique filename with the detected extension
$filename = uniqid('file_') . '.' . $fileExtension;
// Specify the directory where you want to save the file
$uploadDirectory = $filename;
// Write the request body content to the file
$bytesWritten = file_put_contents($uploadDirectory, $requestBody);
// Check if writing to the file was successful
if ($bytesWritten !== false) {
echo json_encode(array("message" => "File uploaded successfully", "filename" => $filename));
} else {
http_response_code(500); // Internal Server Error
echo json_encode(array("error" => "Failed to save file"));
}
} else {
http_response_code(400); // Bad Request
echo json_encode(array("error" => "No data received"));
}
?>