1

Upload File

by
Published Oct 1, 2022
Script webdav
  • Submitted by jaller94 Deno
    Created 1301 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    
    
    3
    export async function main(
    4
        webdav_res: wmill.Resource<"webdav">,
    5
        filePath: string,
    6
        data: string,
    7
    ) {
    8
        const resp = await fetch(
    9
            `${webdav_res.baseUrl}${filePath}`,
    10
            {
    11
                headers: {
    12
                    "Authorization": "Basic " +
    13
                        btoa(webdav_res.user + ":" + webdav_res.password),
    14
                },
    15
                method: "PUT",
    16
                body: Uint8Array.from(atob(data), c => c.charCodeAt(0)),
    17
            },
    18
        );
    19
    
    
    20
        return {
    21
            ok: resp.ok,
    22
            status: resp.status,
    23
            text: await resp.text(),
    24
        };
    25
    }
    26