Created
March 2, 2020 08:52
-
-
Save mfadiilahrio/f326e8596984efd42a36ba374dcee49a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:http/http.dart'; | |
class Upload { | |
final Client client; | |
Upload({this.client}); | |
Future execute(Uri yourFileUri) async { | |
final uri = "https://your_end_point.com/upload"; // URL ENDPOINT KAMU | |
final mimeType = "image/jpeg"; // JENIS FILE YANG AKAN DIKIRIM, KALI INI KITA HARDCODE DULU | |
Map<String, String> uploadHeaders = {'Content-type': mimeType}; // HEADER YANG ENDPOINT KAMU BUTUHIN | |
var uploadResponse = await client.put(Uri.parse(uri), // REQUEST METHODNYA SESUAIIN SAMA ENDPOINT KAMU, ANE PAKE PUT | |
headers: uploadHeaders, | |
body: await File.fromUri(yourFileUri).readAsBytes()); // FILE YANG DIKIRIM DIRUBAH JADI BYTES | |
if (uploadResponse.statusCode == 200) { | |
print("200"); | |
} else { | |
print("Error ${uploadResponse.statusCode}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment