Blasanka / aws_s3_plugin

This is a plugin created for file upload to AWS S3
Other
10 stars 12 forks source link

Failed to upload csv/json file to aws s3 through flutter app #16

Closed rubana28 closed 3 years ago

rubana28 commented 3 years ago

So, I am developing an app using flutter sdk in android studio which will capture the motion sensor data and geolocator data. These data will be stored into a file (csv/ json/ bin) and that file will be uploaded into that specific bucket every 1 hour through my flutter app.

I have tried to upload data into S3 bucket using http class but this is not working. Again, everywhere there are many resources for uploading images. There are less resources for uploading file. I have also tried to use aws lambda but all tutorials are about uploading images.

Can anyone suggest me any way/tutorial/documentation about how can I upload files through my flutter to AWS S3 bucket? A code snippet is given below about how I am trying to upload data into s3 bucket.

` DatabaseHelper db = DatabaseHelper();

static const String _csvHeader = "Accelerometer, UserAccelerometer, Gyroscope, latitude-longitude\n";
List entries = [];

addEntry() async{
  var res = await db.queryGeoAll();  //to get all data of geolocator from database
  var geoCSV = mapListToCsv(res);    //converting them into a csv file
  entries.add("$accelerometer, $userAccelerometer, $gyroscope, $geoCSV");
}

clearEntries() {
  accelerometer= null;
  userAccelerometer= null;
  gyroscope= null;
  latitudeData= null;
  location = null;
  entries.clear();
}

void uploadSensor() async{
  String csvContent = entries.join("\n");
  print(csvContent);

  Uri uri = Uri.parse("Bucket Adress");
  http.MultipartRequest request = new http.MultipartRequest("POST", uri);
  request.files.add(new http.MultipartFile.fromString("csv", _csvHeader + csvContent));

  try {
    return await request.send().then((response) {
      if (response.statusCode == 200) {
        clearEntries();
        return true;
      } else {
        return false;
      }
    });
  } catch (e) {
    print(e.toString());
    //return false;
  }
}`

Here, I am getting an error like: I/flutter ( 394): SocketException: Failed host lookup: 's3.us-east-1.aws.amazonaws.com' (OS Error: No address associated with hostname, errno = 7) I have already added the following line to Android Manifest file <uses-permission android:name="android.permission.INTERNET"/>