'Curl POST upload file test

I have a FastAPI with the following type:

@app.post("/extract_text") 
async def create_upload_file(upload_file: UploadFile = File(...)):
    return FileResponse(path="Outputs/ocr_output.zip", filename="{}".format(main.allinall(upload_file))+"_output.zip", media_type='application/zip')

In browser and with the help of UI that I have, I am able to upoad files and download the output file (return...).

I want to test this on a linux service and I have to test this api through a curl command. I am using this command:

 curl -X 'POST' 'http://localhost/extract_text' -H 'accept: application/json' -H 'Content-Type: multipart/form-data' -F 'file=@demo2_test_imageinput.png;type=application/json'

and here is the error I receive:

{"detail":[{"loc":["body","upload_file"],"msg":"field required","type":"value_error.missing"}]}

input is a png file avaialble in the current folder and output would be a zipfile as the output of allinall function.

when I try this:

curl -i -X POST -H "Content-Type: multipart/form-data" -F "data=@demo2_test_imageinput.png" http://localhost/extract_text

I receive this error:

HTTP/1.1 422 Unprocessable Entity
Server: nginx/1.15.12
Date: Thu, 19 May 2022 20:16:44 GMT
Content-Type: application/json
Content-Length: 95
Connection: keep-alive


Solution 1:[1]

I have three radio buttons.By default first button should be selected.How to set it?

Here is how you do it in reactive forms,

this.yourForm = this.fb.group(
        {
          aircraftWeightSelection: ['FinalPartWeight']
        }
      );

so your component file can look like this,

import { Component } from '@angular/core';
import { 
  FormBuilder,
  FormGroup,
  FormControl
} from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
    title = 'stackoverflow-examples';
    panelOpenState = false;
    yourForm: FormGroup;
    isMaterialWeightNotProvided: boolean = true;

    get aircraftWeightSelectionFormControl(): FormControl {
      // debugger
      return this.yourForm.controls['aircraftWeightSelection'] as FormControl;
    }

    constructor(
      private fb: FormBuilder
    ) { 
      this.yourForm = this.fb.group(
        {
          aircraftWeightSelection: ['FinalPartWeight']
        }
      );
    }

    ngOnInit() {
    }

  OnAircraftWeightSelection(evt: any) {
    // Do your thing here
  }
}

Your HTML file can look like this,

<div class="input" style="padding-top: 1%;">
  <mat-label>Select an option for the calculation</mat-label><br/>
  <mat-radio-group aria-label="weight calculation" [formControl]="aircraftWeightSelectionFormControl" color="primary" (change)="OnAircraftWeightSelection($event)">
    <mat-radio-button style="padding-top: 2%" value="FinalPartWeight">First Part weight</mat-radio-button>
    <mat-radio-button style="padding-top: 2% ;vertical-align: top;" [disabled]='isMaterialWeightNotProvided' value="MaterialWeight">Second Part weight </mat-radio-button>
    <mat-radio-button style="padding-top: 2%; vertical-align: top;" value="PartWeightDifference">Third Part weight</mat-radio-button>
  </mat-radio-group>
</div>

Note: This is just a code sample for your question you may still have to modify this a little :) happy coding !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1