Со стороны приложения я получаю:
Код: Выделить всё
{"error": "Bad Request", "message": "Multipart: Boundary not found", "statusCode": 400}
Код: Выделить всё
[Nest] 29165 - 01/21/2025, 10:34:06 AM ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'imagem')
TypeError: Cannot read properties of undefined (reading 'imagem')
at ReceitasController.create
Код: Выделить всё
static async create(file: any, receita: Receita): Promise {
const formData = new FormData()
formData.append('imagem', {
type: file.mime,
name: file.fileName,
uri:
Platform.OS === 'android' ? file.uri : file.uri.replace('file://', ''),
})
formData.append('data', JSON.stringify(receita))
return http.post('/receitas', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
})
}
Код: Выделить всё
@Post()
@UseInterceptors(
FileFieldsInterceptor([
{ name: 'imagem', maxCount: 1 },
{ name: 'anexos', maxCount: 5 },
]),
)
async create(
@UploadedFiles()
files: { imagem: Express.Multer.File[]; anexos?: Express.Multer.File[] },
@Body() body: { data: string },
@CurrentUser() user: TokenPayload,
) {
const file = files.imagem[0]
const b = JSON.parse(body.data)
const rc = createReceitaSchema.parse(b)
return await this.receitasService.create(
file,
rc,
user.sub,
files.anexos,
)
}
Код: Выделить всё
const http = axios.create({
baseURL: 'http://192.168.1.45:3333/',
withCredentials: true,
}) as APIInstaceProps
[img]https://i.sstatic. net/WQbQXSwX.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/793 ... -not-found