I'm working on a project where user uploads a file during creating the order. The file is sent through AJAX to a view
and then recognized number of words which returns back.
For this purpose, I want to use textract
module. The problem is that I haven't found a way how to add an inmemory uploaded file as an textract.process(filepath)
argument since it wants filepath
, not a file
.
So I suppose I should save this file temporary on the drive and send a path to this file to process
function.
@csrf_exempt
def ajax_file_word_count(request):
from SolutionsForLanguages import word_counter
file = request.FILES.get('file')
count = word_counter.count_words(file)
return JsonResponse({'word_count': count})
How can I do that so the file is immediately deleted after words are counted?