0

Here are my codes, the uploaded file are stored as self.file (which is an Option that converted to String using .into_iter()). But using .into_iter() cause an error stating:

`FormData` is not an iterator
the following trait bounds were not satisfied:
`FormData: Iterator`
which is required by `FormData: IntoIterator`
`&FormData: Iterator`
which is required by `&FormData: IntoIterator`
`&mut FormData: Iterator`
which is required by `&mut FormData: IntoIterator`
`js_sys::Object: Iterator`
which is required by `js_sys::Object: IntoIterator`
`&js_sys::Object: Iterator`
which is required by `&js_sys::Object: IntoIterator`
`&mut js_sys::Object: Iterator`

Here are my codes:

Msg::RequestCreateRecordsData => {
    //LOADING STATUS KE STATE
    self.loading = true;
    ConsoleService::info(&format!("DEBUG loading status : {:?}", &self.loading));

    let form_data = FormData::new().unwrap();
    form_data.append_with_blob("file", self.file.as_ref().unwrap()).unwrap();

    let mut body = String::new();
    for entry in form_data.into_iter() {
        let (name, value) = entry.unwrap();
        let entry = format!("{}={}&", name, value);
        body.push_str(&entry);
    }
    body.pop(); // Remove the trailing '&'

    let url = format!(
        "https://test-dps-api.dev-domain.site/api/document/{}/{}",
        &self.props.app_id,
        &self.props.card_index
    );
    let request = Request::post(url)
        .header("Content-Type", "multipart/form-data")
        .body(Ok(body.into()))
        .expect("Could not build request.");
    let callback = 
        self.link.callback(|response: Response<Json<Result<String, anyhow::Error>>>| {
            let (meta, Json(data)) = response.into_parts();
            match data { 
                Ok(dataok) => {
                    // ConsoleService::info(&format!("data response {:?}", &dataok));
                    Msg::Ignore

                }
                Err(error) => {
                    Msg::ErrorIgnore
                }
            }
        });
        // self.callback_toggle_insertrecord.emit(Msg::ToggleInsertRecord);
        let task = FetchService::fetch(request, callback).expect("failed to start request");


        self.fetch_task = Some(task);
        ConsoleService::info(&format!("Getting Data.."));

    true
}

I've tried to change it to .entries(), .to_string() and .into() and nothing helped. Any help from you guys would be muchly appreciated!

drewtato
  • 6,783
  • 1
  • 12
  • 17

0 Answers0