You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
inventory-app/src/app/upload/vetcove.rs

29 lines
1.1 KiB

use axum::extract::{Multipart, State};
use sqlx::SqlitePool;
use askama_axum::{IntoResponse, Response};
use anyhow::anyhow;
use tracing::info;
use crate::error::AppError;
use crate::session::SessionUser;
use crate::ingest::vetcove::ingest_item_history_bytes;
pub async fn order_details_import(
State(db): State<SqlitePool>,
user: SessionUser,
mut multipart: Multipart,
) -> Result<Response, AppError> {
let mut filename = "".to_owned();
while let Some(field) = multipart.next_field().await? {
filename = field.file_name().ok_or(anyhow!("field missing filename"))?.to_string();
let name = field.name().ok_or(anyhow!("field missing name"))?.to_string();
let content_type = field.content_type().ok_or(anyhow!("field missing content type"))?.to_string();
let data = field.bytes().await?;
info!("Name: {}, file: {}, content: {}, data: {} bytes", name, filename, content_type, data.len());
ingest_item_history_bytes(data, db.clone(), user.id).await?;
}
Ok(format!("File {} uploaded successfully", filename).into_response())
}

Powered by TurnKey Linux.