app/controllers/cas/api/files_controller.rb in cas-cms-1.0.0.alpha1 vs app/controllers/cas/api/files_controller.rb in cas-cms-1.0.0.alpha2
- old
+ new
@@ -3,21 +3,31 @@
def create
if ENV.fetch("S3_BUCKET")
service = "s3"
end
+
metadata = resource_params[:attributes][:metadata]
file = ::Cas::MediaFile.new(
service: service,
- size: metadata[:original][:metadata][:size].to_i,
- original_name: metadata[:original][:metadata][:filename],
- mime_type: metadata[:original][:metadata][:mime_type],
+ size: metadata[:metadata][:size].to_i,
+ original_name: metadata[:metadata][:filename],
+ mime_type: metadata[:metadata][:mime_type],
media_type: resource_params[:attributes][:media_type],
file: metadata.to_json,
- attachable: attachable_record
+ attachable: attachable_record,
+ author: current_user,
)
- file.save
+
+ Rails.logger.debug metadata.inspect
+
+ unless !file.valid?
+ Rails.logger.debug "File upload failed: #{file.errors.inspect}"
+ end
+
+ file.save!
+
Cas::RemoteCallbacks.callbacks[:after_file_upload].call(file)
render json: {
data: {
id: file.id.to_s,
type: "media-files",
@@ -51,28 +61,26 @@
.permit(
attributes: [
:cover,
:media_type,
metadata: [
- original: [
- :id,
- :storage,
- metadata: [:size, :filename, :mime_type, 'mime-type']
- ]
+ :id,
+ :storage,
+ metadata: [:size, :filename, :mime_type, 'mime-type']
]
],
relationships: [
attachable: [
data: [:id, :type]
]
]
)
if r[:attributes][:metadata].present?
- if r[:attributes][:metadata][:original][:metadata][:mime_type].blank?
- r[:attributes][:metadata][:original][:metadata][:mime_type] = r[:attributes][:metadata][:original][:metadata][:"mime-type"]
+ if r[:attributes][:metadata][:metadata][:mime_type].blank?
+ r[:attributes][:metadata][:metadata][:mime_type] = r[:attributes][:metadata][:metadata][:"mime-type"]
end
- r[:attributes][:metadata][:original][:metadata].delete(:"mime-type")
+ r[:attributes][:metadata][:metadata].delete(:"mime-type")
end
r
end
def attachable_record