Guest User

Untitled

a guest
May 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. [HttpPost("upload")]
  2. public virtual async Task<IActionResult> PostMulti(Int64 parentId, ICollection<IFormFile> fileData)
  3. {
  4. foreach (var file in fileData) {
  5. await SaveFile(file, parent);
  6. }
  7.  
  8. return Created("", Map(Repository.Get(parentId)));
  9. }
  10.  
  11. const formData = new FormData();
  12. formData.append('image', this.state.file);
  13.  
  14. console.log("this.state.file = ", this.state.file);
  15. console.log("formData = ", formData);
  16.  
  17. axios({
  18. url: `/api/gameMethods/playerStates/${this.props.playerId}/files/upload`,
  19. method: 'POST',
  20. data: formData,
  21. headers: {
  22. Accept: 'application/json',
  23. 'Content-Type': 'multipart/form-data'
  24. }
  25. })
  26. .then((response) => {
  27. //handle success
  28. console.log('response -- then: ', response);
  29. this.setState({
  30. file: this.state.file
  31. });
  32. })
  33. .catch((response) => {
  34. //handle error
  35. console.log('response -- catch: ', response);
  36. });
  37.  
  38. const filesToSubmit = []
  39. filesToSubmit.push((new FormData()).append('image', this.state.file))
  40.  
  41. axios({
  42. url: `/api/gameMethods/playerStates/${this.props.playerId}/files/upload`,
  43. method: 'POST',
  44. data: {formData : filesToSubmit},
  45. headers: {
  46. Accept: 'application/json',
  47. 'Content-Type': 'multipart/form-data'
  48. }
  49. })
  50.  
  51. axios({
  52. url: myUrl,
  53. method: 'POST',
  54. data: `email=${myEmail}`,
  55. headers: {
  56. 'Content-Type': 'application/x-www-form-urlencoded'
  57. }
  58. })
  59. .then(response => {
  60. console.log(response);
  61. })
  62. .catch(error => {
  63. console.error(error);
  64. });
Add Comment
Please, Sign In to add comment