Las imágenes pueden enviarse en cualquier formato y siempre están vinculadas a un pedido. Es posible crear un pedido ya con las imágenes, o bien agregar imágenes a un pedido existente.
Crear pedido con imágenes
El controller de pedidos permite crear pedidos con imágenes accediendo a la action "create".
Ejemplo con CURL:curl -X POST "https://max.cfaz.net/api/v1/requests" \
-d "access_token=0cd675768fev8dab81fe1c1297d56b09" \
-d "request[clinic_id]=19" \
-d "request[request_status_id]=53" \
-d "request[date]=2021-01-10T16:30" \
-d "request[dentist_datum][name]=João das Couves" \
-d "request[patient_datum][name]=Maria das Couves" \
-d "request[patient_datum][gender]=true" \
-d "request[patient_datum][birthdate]=1995-01-01" \
-d "request[photos_attributes][1][image]=@/path/image1.jpg" \
-d "request[photos_attributes][2][image]=@/path/image2.jpg" \Ejemplo con la Gem RestClient:RestClient.post "https://max.cfaz.net/api/v1/requests",
{ request:
{ clinic_id: 19,
request_status_id: 53,
date: "2021-01-10T16:30",
dentist_datum: { name: "João das Couves" },
patient_datum: { name: "Maria das Couves", gender: true, birthdate: "1995-01-01"},
photos_attributes: [
{ "1": { image: File.open("/path/image.jpg"),
image_file_name: "image1.jpg",
image_content_type: "image/jpg"}},
{ "2": { image: File.open("/path/image.jpg"),
image_file_name: "image2.jpg",
image_content_type: "image/jpg"}}
],
}
},
"authorization" => "Token token=0cd675768fev8dab81fe1c1297d56b09"Agregar imágenes a un pedido existente
El controller de pedidos permite agregar imágenes a un pedido accediendo a la action "update".
Ejemplo con CURL:curl -X PUT https://max.cfaz.net/api/v1/requests/{request_id} \
-d "access_token=0cd675768fev8dab81fe1c1297d56b09" \
-d "request[photos_attributes][1][image]=@/path/image1.jpg" \
-d "request[photos_attributes][2][image]=@/path/image2.jpg" Ejemplo con la Gem RestClient:RestClient.put "https://max.cfaz.net/api/v1/requests/{request_id}",
{ request: {
photos_attributes: [
{ "1": { image: File.open("/path/image.jpg"),
image_file_name: "image1.jpg",
image_content_type: "image/jpg"}
},
{ "2": { image: File.open("/path/image.jpg"),
image_file_name: "image2.jpg",
image_content_type: "image/jpg"}}
],
}},
"authorization" => "Token token=0cd675768fev8dab81fe1c1297d56b09"Eliminar imágenes de un pedido existente
El controller de pedidos permite eliminar imágenes de un pedido accediendo a la action "update".
Ejemplo con CURL:curl -X PUT http://localhost:3000/api/v1/requests/{request_id} \
-d "access_token=0cd675768fev8dab81fe1c1297d56b09" \
-d "request[photos_attributes][1][id]={photo_id}" \
-d "request[photos_attributes][1][_destroy]=1"Ejemplo con la Gem RestClient:RestClient.put "https://max.cfaz.net/api/v1/requests/{request_id}",
{ request: {
id: {request.id},
photos_attributes: [
{ id: {photo.id},
_destroy: true
},
],
}
},
"authorization" => "Token token=0cd675768fev8dab81fe1c1297d56b09"¿Le fue útil este artículo?
¡Qué bueno!
Gracias por sus comentarios
¡Sentimos mucho no haber sido de ayuda!
Gracias por sus comentarios
Comentarios enviados
Agradecemos su iniciativa, e intentaremos corregir el artículo