Filename is always null when posting a new media file
Always when I upload a new media file, the fildset file name in mongo becomes null.
I used curl, postman and python request library but always the result is the same :(
Definition in settings.py:
EXTENDED_MEDIA_INFO = ['content_type', 'name', 'length']
(I tried with "filename" too)
And the definition:
files = {
'item_title': 'file',
'auth_field': 'account_id',
'schema': {
'title': {
'type': 'string',
},
'account_id': {
'type': 'objectid',
'required': True,
'data_relation': {
'resource': 'accounts',
'field': '_id',
}
},
'file': {
'type': 'media',
'required': True,
},
'tags': {
'type': 'list',
'schema': {
'type': 'string',
},
},
}
}
When I use curl like in your web example:
curl -F "account_id=553a0b0f8a6f501695fa8b42" -F "file=@blua.jpg" http://localhost:5000/files
{"_updated": "Thu, 30 Apr 2015 21:47:51 GMT", "_links": {"self": {"href": "files/5542a3078a6f5064a3a04dba", "title": "file"}}, "_created": "Thu, 30 Apr 2015 21:47:51 GMT", "_status": "OK", "_id": "5542a3078a6f5064a3a04dba", "_etag": "90314f9491a92dc84aa90880d69e2b76bfd947db"}
Mongo stores:
> db.fs.files.find({}).pretty()
{
"_id" : ObjectId("5542a54f8a6f5064a3a04dbb"),
"contentType" : "image/jpeg",
"chunkSize" : 261120,
"filename" : null, <-------------------- THE PROBLEM
"length" : 437658,
"uploadDate" : ISODate("2015-04-30T21:57:35.080Z"),
"md5" : "90dce7915217108434acd61b3285d907"
}
> db.files.find({}).pretty()
{
"_id" : ObjectId("5542a54f8a6f5064a3a04dbe"),
"_updated" : ISODate("2015-04-30T21:57:35Z"),
"account_id" : ObjectId("553a0b0f8a6f501695fa8b42"),
"file" : ObjectId("5542a54f8a6f5064a3a04dbb"),
"_created" : ISODate("2015-04-30T21:57:35Z"),
"_etag" : "466ab27d09d6eb87d2c0ab5f094875011e72cca2"
}
Using python requests [ http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file] :
def file_post(token, account_id, filename, content, mimetype, debug=True):
path = __path__
url = Bkend.url(path)
headers = {'Authorization': Rest.authorization(token)}
payload = {'account_id': account_id}
resp = requests.post(
url=url,
headers=headers,
data=payload,
files={'file': (secure_filename(filename), content, mimetype)}
#files={'file': ('filename', content, mimetype)}
#files={'file': content}
)
if debug:
log = "\n - Url: " + str(url) + \
"\n - Headers:" + str(headers) + \
"\n - Payload/Params:" + json.dumps(payload) + \
"\n\n...............................\n" + \
"\n - Resp Status Code: " + str(resp.status_code) + \
"\n - Resp URL: " + str(resp.url) + \
"\n - Resp Headers: " + str(resp.headers) + \
"\n - Resp Avg: " + str(resp.elapsed) + \
"\n - Resp Body: \n" + resp.text
capp.logger.debug(log)
return resp
I even tested explicitly to specify the filename, content_type and headers, but always get the same result
> db.files.find({}).pretty()
{
"_id" : ObjectId("5542a86c8a6f5064a3a04dce"),
"_updated" : ISODate("2015-04-30T22:10:52Z"),
"account_id" : ObjectId("553a0b0f8a6f501695fa8b42"),
"file" : ObjectId("5542a86c8a6f5064a3a04dbf"),
"_created" : ISODate("2015-04-30T22:10:52Z"),
"_etag" : "d5a203b20dc75a8ae8691cd8cfecb627da9a181b",
"tags" : [
"STOP",
"BUS",
"MELON"
],
"title" : "The bus stop"
}
> db.fs.files.find({}).pretty()
{
"_id" : ObjectId("5542a86c8a6f5064a3a04dbf"),
"contentType" : "application/pdf",
"chunkSize" : 261120,
"filename" : null, <-------------- THE PROBLEM
"length" : 3589703,
"uploadDate" : ISODate("2015-04-30T22:10:52.507Z"),
"md5" : "f2176c1780b32b549ca7513893254c06"
}
>
With the postman:
Result in mongo with the same end:
> db.files.find({}).pretty()
{
"_id" : ObjectId("5542aa768a6f5064a3a04de1"),
"_updated" : ISODate("2015-04-30T22:19:34Z"),
"account_id" : ObjectId("553a0b0f8a6f501695fa8b42"),
"file" : ObjectId("5542aa768a6f5064a3a04ddf"),
"_created" : ISODate("2015-04-30T22:19:34Z"),
"_etag" : "d6a3ba5ad5f6fb7ef6557000841194501815e39a"
}
> db.fs.files.find({}).pretty()
{
"_id" : ObjectId("5542aa768a6f5064a3a04ddf"),
"contentType" : "application/pdf",
"chunkSize" : 261120,
"filename" : null, <------ The problem again
"length" : 16651,
"uploadDate" : ISODate("2015-04-30T22:19:34.269Z"),
"md5" : "20ef57d98d4bc11ab55a260a4d75b727"
}
>
Any idea? is this a bug or am I doing something wrong?
Solved not done in version 0.5.3 and fixed in version 0.5.4
source to share
This is probably due to this ticket , which was closed 13 days ago. Try to pull 0.5.4 out of Eve, it should fix your problem.
source to share