Last active
November 4, 2017 02:28
-
-
Save joncloud/d3ee6e8b73031232084a97e1a7d756b1 to your computer and use it in GitHub Desktop.
File Upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const formData = new FormData(); | |
| const blob = new Blob(['a', 'b', 'c', 'd']); | |
| formData.append("image", blob); | |
| formData.append('message', 'my message'); | |
| formData.append('visibility', 'shown'); | |
| formData.append('replyStatusId', '123'); | |
| formData.append('sensitive', 'true'); | |
| formData.append('spoilerText', '**SPOILERS**'); | |
| this.http.post('/home/upload', formData) | |
| .subscribe(x => { | |
| console.log(x); | |
| }, | |
| y => { | |
| console.log(y); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jdber_000@JDB-MACBOOK-PRO ~ [07:28:07 PM] ❯ get-content .\test.txt | http -f post localhost:57710/home/upload "Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryqdjmAO6IpAjcUzuO" | |
| HTTP/1.1 200 OK | |
| Content-Type: application/json; charset=utf-8 | |
| Date: Sat, 04 Nov 2017 02:28:15 GMT | |
| Server: Kestrel | |
| Transfer-Encoding: chunked | |
| { | |
| "files": [], | |
| "model": { | |
| "message": "my message", | |
| "replyStatusId": "123", | |
| "sensitive": true, | |
| "spoilerText": "**SPOILERS**", | |
| "visibility": "shown" | |
| } | |
| } | |
| jdber_000@JDB-MACBOOK-PRO ~ [07:28:15 PM] ❯ get-content .\test.txt | http -f post localhost:57710/home/upload | |
| HTTP/1.1 200 OK | |
| Content-Type: application/json; charset=utf-8 | |
| Date: Sat, 04 Nov 2017 02:28:17 GMT | |
| Server: Kestrel | |
| Transfer-Encoding: chunked | |
| { | |
| "files": [], | |
| "model": { | |
| "message": null, | |
| "replyStatusId": null, | |
| "sensitive": false, | |
| "spoilerText": null, | |
| "visibility": null | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Accept:application/json, text/plain, */* | |
| Accept-Encoding:gzip, deflate, br | |
| Accept-Language:en-US,en;q=0.8 | |
| Connection:keep-alive | |
| Content-Length:716 | |
| Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| DNT:1 | |
| Host:localhost:57710 | |
| Origin:http://localhost:57710 | |
| Referer:http://localhost:57710/counter | |
| User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| Content-Disposition: form-data; name="image"; filename="blob" | |
| Content-Type: application/octet-stream | |
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| Content-Disposition: form-data; name="message" | |
| my message | |
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| Content-Disposition: form-data; name="visibility" | |
| shown | |
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| Content-Disposition: form-data; name="replyStatusId" | |
| 123 | |
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| Content-Disposition: form-data; name="sensitive" | |
| true | |
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9 | |
| Content-Disposition: form-data; name="spoilerText" | |
| **SPOILERS** | |
| ------WebKitFormBoundaryTZqByEQR1v3Zmyb9-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Content-Type:application/json; charset=utf-8 | |
| Date:Sat, 04 Nov 2017 02:16:02 GMT | |
| Server:Kestrel | |
| Transfer-Encoding:chunked |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "model": { | |
| "message": "my message", | |
| "visibility": "shown", | |
| "replyStatusId": "123", | |
| "sensitive": true, | |
| "spoilerText": "**SPOILERS**" | |
| }, | |
| "files": [{ | |
| "contents": "abcd", | |
| "name": "image" | |
| }] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MastodonPostRequest | |
| { | |
| public string Message { get; set; } | |
| public string Visibility { get; set; } | |
| public string ReplyStatusId { get; set; } | |
| public bool Sensitive { get; set; } | |
| public string SpoilerText { get; set; } | |
| } | |
| [HttpPost] | |
| public IActionResult Upload([FromForm]MastodonPostRequest model) | |
| { | |
| var files = Request.Form.Files.Select(file => | |
| { | |
| using (var stream = file.OpenReadStream()) | |
| using (var reader = new StreamReader(stream)) | |
| { | |
| return new | |
| { | |
| Contents = reader.ReadToEnd(), | |
| Name = file.Name | |
| }; | |
| } | |
| }).ToList(); | |
| return Ok(new | |
| { | |
| model, | |
| files | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment