I am working on a Flutter app trying to upload images and videos to an AWS Ubuntu instance.
This is the function to upload the file to the server:
void _upload(File file) {
if (file == null) return;
setState(() {
});
String base64Image = base64Encode(file.readAsBytesSync());
String fileName = file.path.split("/").last;
http.post(phpEndPoint, body: {
"image": base64Image,
"name": fileName,
}).then((res) async {
print(res.statusCode);
setState(() {
print("***********SOURCE subido:"+this.source.toString());
if(this.source.toString() == "MediaSource.image"){
Toast.show(
"Imagen subida", context,
duration: Toast.LENGTH_LONG,
gravity: Toast.CENTER,
backgroundColor: Color(0xff01A0C7),
textColor: Colors.white);
incrementNumFotos(context);
}
if(this.source.toString() == "MediaSource.video"){
Toast.show(
"Video subido", context,
duration: Toast.LENGTH_LONG,
gravity: Toast.CENTER,
backgroundColor: Color(0xff01A0C7),
textColor: Colors.white);
incrementNumVideos(context);
}
});
}).catchError((err) {
print(err);
});
}
This is the PHP script that receives and stores the sended file:
<?php
$image = $_POST['image'];
$name = $_POST['name'];
$realImage = base64_decode($image);
file_put_contents($name,$realImage);
echo "OK";
?>
The issue that I am having is that the large files are not stored.
I have updated the file php.ini at the server:
upload_max_filesize = 128M
post_max_size =64M
max_execution_time = 300
max_input_time = 300
I have tried to upload files with different filesize.
A file with size = 5313566 bytes is uploaded. A file with size = 8891426 bytes is not uploaded.