I am trying to imitate this in Xcode using Alamofire:
Here is what I created on Swift/Xcode according to Alamofire docs :
let url = "http://127.0.0.1:8000/" /* your API url */
AF.upload(multipartFormData: { multipartFormData in
multipartFormData.append(Data("one".utf8), withName: "file")
}, to: url, method: .post)
.responseJSON { response in
debugPrint(response)
}
The response I get from the server is. "Number of Files: " = 0;
Meaning the server is not receiving the file, however it works when I do it from Postman, so what am I missing?
Also here is my django server which is taking the request, if this is needed:
@csrf_exempt
def test(request):
length = 0
try:
length = len(request.FILES)
except Exception as e:
print(e)
return JsonResponse({'Number of Files: ': length})
2
Answers
I found the solution! for anyone else who might be facing this problem, heres why:
You just have to specify the filename too.