Created
October 4, 2020 15:43
-
-
Save emiliodallatorre/8772263a290bc30f592bc9cf27872c48 to your computer and use it in GitHub Desktop.
Funzione per caricare un file via http con Flutter.
This file contains 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 'package:http/http.dart' as http; | |
class HttpUploader { | |
Future<void> uploadFile (File file, String nameOnPrinter) async { | |
String url = "http://192.168.1.125/upload?X-Filename=$nameOnPrinter.gcode"; | |
Map<String, String> headers = { | |
"Content-Type": "application/octet-stream" | |
}; | |
// Qui otteniamo un formato di file più facile da trasmettere. | |
Uint8List fileAsBytes = file.readAsBytesSync(); | |
// Qui effettivamente il file viene trasmesso, e si ottiene una risposta dalla stampante. | |
http.Response response = await http.post( | |
url, | |
headers: headers, | |
body: bytes, | |
); | |
debugPrint(response.body); | |
debugPrint(response.statusCode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment