Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
image board
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
random asynchronous nightmare distributor
image board
Commits
db9cc3c4
Commit
db9cc3c4
authored
3 years ago
by
Ophestra
Browse files
Options
Downloads
Patches
Plain Diff
potential fix of multipart form submit
parent
4a62b452
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/image.go
+23
-7
23 additions, 7 deletions
client/image.go
with
23 additions
and
7 deletions
client/image.go
+
23
−
7
View file @
db9cc3c4
...
...
@@ -2,6 +2,8 @@ package client
import
(
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"random.chars.jp/git/image-board/api"
...
...
@@ -17,13 +19,21 @@ func (r *Remote) Images() ([]string, error) {
}
// ImageAdd adds an image to Remote and returns a store.Image.
func
(
r
*
Remote
)
ImageAdd
(
data
[]
byte
)
(
store
.
Image
,
error
)
{
func
(
r
*
Remote
)
ImageAdd
(
reader
io
.
Reader
)
(
store
.
Image
,
error
)
{
if
c
,
ok
:=
reader
.
(
io
.
Closer
);
ok
{
defer
func
()
{
if
err
:=
c
.
Close
();
err
!=
nil
{
fmt
.
Printf
(
"Error closing Closer, %s"
,
err
)
}
}()
}
buf
:=
&
bytes
.
Buffer
{}
w
:=
multipart
.
NewWriter
(
buf
)
if
f
,
err
:=
w
.
CreateFormFi
l
e
(
"image"
,
""
);
err
!=
nil
{
if
f
,
err
:=
w
.
CreateFormFie
ld
(
"image"
);
err
!=
nil
{
return
store
.
Image
{},
err
}
else
{
if
_
,
err
=
f
.
Write
(
data
);
err
!=
nil
{
if
_
,
err
=
io
.
Copy
(
f
,
reader
);
err
!=
nil
{
return
store
.
Image
{},
err
}
}
...
...
@@ -32,12 +42,18 @@ func (r *Remote) ImageAdd(data []byte) (store.Image, error) {
return
store
.
Image
{},
err
}
if
re
sp
,
err
:=
r
.
r
equest
(
http
.
MethodPost
,
api
.
Image
,
buf
);
err
!=
nil
{
if
re
q
,
err
:=
http
.
NewR
equest
(
http
.
MethodPost
,
r
.
URL
(
api
.
Image
)
,
buf
);
err
!=
nil
{
return
store
.
Image
{},
err
}
else
{
var
image
store
.
Image
err
=
unmarshal
(
resp
.
Body
,
&
image
)
return
image
,
err
req
.
Header
.
Set
(
"Content-Type"
,
w
.
FormDataContentType
())
var
resp
*
http
.
Response
if
resp
,
err
=
r
.
send
(
req
);
err
!=
nil
{
return
store
.
Image
{},
err
}
else
{
var
image
store
.
Image
err
=
unmarshal
(
resp
.
Body
,
&
image
)
return
image
,
err
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment