Created
May 9, 2019 14:32
-
-
Save devxpy/19b8794762df87a01fc9c92e5263bef3 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
from rest_framework.parsers import FileUploadParser, MultiPartParser | |
from rest_framework.views import APIView | |
from rest_framework.response import Response | |
class FileUploadView(APIView): | |
parser_classes = (FileUploadParser, MultiPartParser) | |
def put(self, request, filename, format=None): | |
with open("uploaded_file", "wb") as f: | |
f.write(request.data['file'].read()) | |
return Response(status=204) | |
--- | |
from rest_api.views import FileUploadView | |
urlpatterns = [ | |
url(r"^upload/(?P<filename>[^/]+)$", FileUploadView.as_view()), | |
] |
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 'package:http/http.dart' as http; | |
import 'package:image_picker/image_picker.dart'; | |
main() async { | |
var image = await ImagePicker.pickImage(source: ImageSource.camera); | |
final res = await http.put( | |
"http://127.0.0.1:8000/api/upload/test", | |
body: await image.readAsBytes(), | |
); | |
print(res.statusCode); | |
print(res.body); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment