I have background process - read excel file and save data from this file. I need to do read file in the background process. But i have error InMemoryUploadedFile
.
My code
def create(self, validated_data):
company = ''
file_type = ''
email = ''
file = validated_data['file']
import_data.delay(file=file,
company=company,
file_type=file_type,
email=email)
my method looks like
@app.task
def import_data(
file,
company,
file_type,
email):
// some code
But i have error InMemoryUploadedFile
.
How i can to send a file to cellery without errors?
When you delay a task, Celery will try to serialize the parameters which in your case a file is included.
Files and especially files in memory can't be serialized.
So to fix the problem you have to save the file and pass the file path to your delayed function and then read the file there and do your calculations.