tauri-apps / tauri-apps/plugins-workspace
Tauri plugin upload error ""error decoding response body: EOF while parsing a value at line 1 column 0"
- Dominant language
- Rust
- Stars
- 1.8k
- Forks
- 602
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 9
Description
I'm getting this error when using tauri-plugin-upload
[Screencast from 2024-02-11 03-22-57.webm](https://github.com/tauri-apps/plugins-workspace/assets/506491/8533e5ac-6112-4edf-8040-074b492a1ea0)
The files get loaded when the user selects a folder and the uploading starts from the top. The first file gets uploaded and at the end of the first file upload I get this error "error decoding response body: EOF while parsing a value at line 1 column 0" and everything stops, nothing gets uploaded after that. The first file fully gets uploaded without any issue though.
The files are being uploaded to a nextcloud server using webdav. nextcloud uses put verb to upload files. please check here https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html#response-headers
so I had to create a separate repo cloned from the tauri-plugin-upload and just change from post to put
I've implemented the code as per the documentation.
Here is the app repository
https://github.com/anver/gbtest
and i've included the plugin inline into the main repo, you can download the plugin repo from here https://github.com/anver/tauri-plugin-gotbackup
This plugin repo is same as the tauri-plugin-upload except for the upload.post verb. i'm using upload.put verb which the nextcloud webdav protocol is using.
I created my own implementation using ureq, which is pretty good but i don't know how to create the progressevent emitter
here is my new code
```rust
use serde::{ ser::Serializer, Serialize };
use tauri::{ command, plugin::{ Builder, TauriPlugin }, Runtime, Window };
use std::collections::HashMap;
use std::fs::File as StdFile;
use ureq;
use std::io::BufReader;
type Result = std::result::Result;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)] Io(#[from] std::io::Error),
#[error(transparent)] Request(#[from] reqwest::Error),
#[error("{0}")] ContentLength(String),
}
impl Serialize for Error {
fn serialize(&self, serializer: S) -> std::result::Result where S: Serializer {
serializer.serialize_str(self.to_string().as_ref())
}
}
#[command]
async fn upload(
_window: Window,
_id: u32,
url: &str,
file_path: &str,
headers: HashMap
) -> Result {
let file = StdFile::open(file_path)?;
let buffered_reader = BufReader::new(file);
let req = ureq
::put(url)
.set("Content-Type", "application/octet-stream")
.set("Authorization", headers.get("Authorization").unwrap_or(&"".to_string()))
.set("OC-Checksum", headers.get("OC-Checksum").unwrap_or(&"".to_string()))
.send(buffered_reader);
if req.ok().is_some() {
Ok(serde_json::json!({ "status": "success" }))
} else {
Err(Error::ContentLength("Content-Length header is required".to_string()))
}
}
// Initializes the plugin.
pub fn init() -> TauriPlugin {
Builder::new("gotbackup").invoke_handler(tauri::generate_handler![upload]).build()
}
```
The upload is working fine now but if someone can add the progress event emitter like in the official plugin it would be gr8 :)
Contributor guide
Assessment
This issue has not been assessed yet.