Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Help supporting v7 #31

Open
mnavarrocarter opened this issue Sep 10, 2021 · 5 comments
Open

Help supporting v7 #31

mnavarrocarter opened this issue Sep 10, 2021 · 5 comments

Comments

@mnavarrocarter
Copy link

Hey, at my company we are in dire need for this SDK to support v7.

I'm willing to contribute to make support happen, but I don't know where to start.

If you could point me to what does need to be done in order to support v7 then I'll be more than happy to submit a PR.

How does that sound? 😃

@gulien
Copy link
Contributor

gulien commented Sep 13, 2021

Hello @mnavarrocarter, thanks for your interest in Gotenberg 😄

The API primarily consists of multipart/form-data endpoints, so this client is mainly a multipart/form-data request builder.

Honestly, I'm not sure that using an SDK is required to interact with Gotenberg; it helps a bit, but you might have more flexibility by directly creating "native" multipart/form-data requests in your application.

Anyway, if an SDK makes sense in your case, you may either:

  • Create your repository (and add it to the awesome-list 😎 )
  • Update this repository

IMO the key will be to mimic the module's organization from Gotenberg (i.e., endpoints per module).

@mnavarrocarter
Copy link
Author

Hi @gulien, thanks for your reply!

I'm mid way of coding our own implementation of the html endpoint. It would be nice If I can help the community porting some of that. But if you think is not necessary, that's fine with me. 😃

@gulien
Copy link
Contributor

gulien commented Sep 13, 2021

Your call 😄 but I think it might help others indeed.

@ju-popov
Copy link

ju-popov commented Jan 6, 2022

It is morally important to support v7 👯‍♀️

@export-mike
Copy link

Raw HTML example:

package main

import (
	"bytes"
	"fmt"
	"io"
	"mime/multipart"
	"net/http"
	"os"
	"strings"
)

func main() {
	reader := strings.NewReader("<h1>hi</h1>")
	buf := new(bytes.Buffer)
	writer := multipart.NewWriter(buf)
	part, err := writer.CreateFormFile("file", "index.html")
	if err != nil {
		panic(err)
	}
	_, err = io.Copy(part, reader)
	if err != nil {
		panic(err)
	}
	fmt.Println(buf.String())
	writer.Close()

	req, err := http.NewRequest("POST", "http://localhost:3000/forms/chromium/convert/html", buf)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", writer.FormDataContentType())

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	if res.StatusCode != http.StatusOK {
		panic(fmt.Errorf("bad status: %s", res.Status))
	}
	defer res.Body.Close()
	out, err := os.Create("index.pdf")
	if err != nil {
		panic(err)
	}
	defer out.Close()
	io.Copy(out, res.Body)
	return
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants