 							if res2.status isnt 201
 								ret = new Error(res.text)
 								return next ret
-							fileModel.save (err, saved) ->
+							fileModel.save (err, savedFile) ->
 								if err
 									ret = new Error("Error saving file to database")
 									ret.cause = err
 									ret.status = 400
 									return next ret
-								res.status 201
-								res.header 'Location', fileModel.uri()
-								res.send '@link': fileModel.uri()
+								entityModel.set 'file', savedFile
+								entityModel.save (err, savedEntity) ->
+									if err
+										ret = new Error("Error saving entity to database")
+										ret.cause = err
+										ret.status = 400
+										return next ret
+									log.debug "Created entity: #{savedEntity}"
+									res.status 201
+									res.header 'Location', fileModel.uri()
+									res.send '@link': fileModel.uri()
 
 	done()

					done()
				, (err) ->
					tags = []
					if 'tags' of fields
						tags = fields['tags']
					fileModel.set 'size', fileField['size']
					fileModel.set 'tags', tags
					fileModel.set 'mediaType', fields['mediaType']

			tags: ['essential']
			summary: "Upload a file"
			description: "Upload a file and store it as an InfolisFile resource."
			consumes: ['multipart/form-data']
			parameters: [
				{
					name: 'file'
