>
> I am working on an application in which I need to upload a file using
> Golang and Angular 4.Suppose I have an input type file and an upload button
> on the screen. When I browse a file from my system and clicks upload
> button.Now following are my queries regarding file upload:
>
> 1. How will angular process the file at front end?
>

Why should your angular frontend process the file at all?

2. If it processes the file then what it will return to the rest api as
> data.
>

The easiest way, I guess, will be a simple form based upload. The file will
be uploaded to the endpoint you specify. Thats a POST action.

The handler responsible for the upload can copy the request body in a file
object and you are done.

```
r *http.Request
file, handler, err := r.FormFile("fileupload")
f, err := os.OpenFile(somePath+"/"+handler.Filename, os.O_WRONLY|os.O_CREATE
, 0644)
_, err = io.Copy(f, file)
```

4. Can file be uploaded via angular script and it will give download url to
> rest api?
>

Its upon your code what you write into the response. Of course could you
return the file location where you did save the file.

5. The uploaded file should not be executable.
>

Look at the flags I set in os.Open(). There you control if a file will be
executable or not. But that is only relevant for the server you save your
files.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to