I uploaded a program on which a django application is used for file uploading and used the chunk file uploads for it (with the blueimp fileupload on JS side).
When I tested my application locally, it works. When I do it on the IIS production, I always get this error:
POST http://URL/api/chunked_upload/ 500 (Internal Server Error)
The logs in the IIS were not helpful either.
JS Code:
$('#fileUpload').fileupload({
url: window.location.href + 'api/chunked_upload/',
dataType: "json",
maxChunkSize: 100000, // Chunks of 100 kB
formData: form_data,
type: 'POST',
add: function (e, data) {
form_data.splice(1);
calculate_md5(data.files[0], 100000);
$("#submitButton").off('click').on("click", function () {
showLoading()
data.submit();
});
},
chunkdone: function (e, data) { // Called after uploading each chunk
if (form_data.length < 2) {
form_data.push(
{"name": "upload_id", "value": data.result.upload_id}
);
}
},
done: function (e, data) { // Called when the file has completely uploaded
let formInput;
$.ajax({
type: "POST",
url: window.location.href + 'api/chunked_upload_complete/',
data: {
csrfmiddlewaretoken: csrf,
upload_id: data.result.upload_id,
md5: md5
},
dataType: "json",
success: function(data) {
inputForm = document.getElementById('ddGraderForm')
document.getElementById('id_formFile').value = data['file']
inputForm.submit()
}
});
},
});
Django urls
urlpatterns = [
path('', views.webinterfaceViews, name='main'),
path('api/chunked_upload_complete/', FastaFileUploadCompleteView.as_view(), name='api_chunked_upload_complete'),
path('api/chunked_upload/', FastaFileUploadView.as_view(), name='api_chunked_upload'),
]
Django view
class FastaFileUploadView(ChunkedUploadView):
model = fileUpload
def check_permissions(self, request):
# Allow non authenticated users to make uploads
pass
class FastaFileUploadCompleteView(ChunkedUploadCompleteView):
model = fileUpload
def check_permissions(self, request):
# Allow non authenticated users to make uploads
pass
def on_completion(self, uploaded_file, request):
# Do something with the uploaded file. E.g.:
# * Store the uploaded file on another model:
# SomeModel.objects.create(user=request.user, file=uploaded_file)
# * Pass it as an argument to a function:
# function_that_process_file(uploaded_file)
pass
def get_response_data(self, chunked_upload, request):
return {'file': chunked_upload.file.name, 'filename': chunked_upload.filename}
The error code I receive is BytesReceived="0", ErrorCode="Reached the end of the file. (0x80070026)"
Headers="Content-Type: text/html Vary: Cookie Server: Microsoft-IIS/10.0 X-Frame-Options: DENY X-Content-Type-Options: nosniff Referrer-Policy: same-origin X-Powered-By: ASP.NET "