【发布时间】:2017-01-25 10:13:27
【问题描述】:
我正在处理一个用户在创建订单期间上传文件的项目。该文件通过 AJAX 发送到view,然后识别返回的字数。
为此,我想使用textract 模块。问题是我还没有找到一种方法来添加内存中上传的文件作为textract.process(filepath) 参数,因为它需要filepath,而不是file。
所以我想我应该将此文件临时保存在驱动器上并将该文件的路径发送到process函数。
@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})
我该怎么做才能在计算字数后立即删除文件?
【问题讨论】:
标签: python django django-file-upload