Guest User

Untitled

a guest
Sep 19th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. // Endpoints start here ... ironic right?
  2. @RestController
  3. @CrossOrigin(origins = {"http://localhost:8080", "http://a.example.com"})
  4. public class FileController {
  5. private static final Logger logger = LoggerFactory.getLogger(FileController.class);
  6.  
  7. @Autowired
  8. private FileStorageService fileStorageService;
  9.  
  10. // Upload file endpoint
  11. // POST
  12. @PostMapping("/uploadfile")
  13. .
  14. .
  15. .
  16.  
  17.  
  18. }
  19.  
  20. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api-test.cubereum.com/fileupload/uploadfile. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).[Learn More]
  21.  
  22. var max_fields = 10;
  23. var wrapper = $(".input_fields_wrap");
  24. var add_button = $(".add_field_button");
  25. var x = 0;
  26.  
  27. $(add_button).click(function(e){
  28. e.preventDefault();
  29. if(x < max_fields){
  30. x++;
  31. $(wrapper).append(`
  32. <span>
  33. <br>
  34. <div class="row" id="field[${x}]">
  35. <div class="col">
  36. <input type="text" name="fileName" id="field[${x}]-fileName" class="form-control" placeholder="File name">
  37. </div>
  38. <div class="col">
  39. <div class="custom-file">
  40. <input type="file" class="custom-file-input" name="fileUpload" id="field[${x}]-fileUpload" aria-describedby="inputGroupFileAddon01">
  41. <label class="custom-file-label" for="fileUpload">Choose file</label>
  42. </div>
  43. </div>
  44. <div class="col">
  45. <input type="text" id="field[${x}]-fileUploadURL" name="fileUploadURL" class="form-control" placeholder="File URL" readonly>
  46. </div>
  47. <div class="col">
  48. <button class="remove_field btn"> Remove Field </button>
  49. </div>
  50. </div>
  51. </span>
  52. <script>
  53. document.getElementById("field[${x}]-fileUpload").onchange = function(e) {
  54. e.preventDefault();
  55. console.log("FILE UPLOAD OF field[${x}]");
  56.  
  57. var filePath = $(this).val();
  58. var form = new FormData();
  59. form.append("file", filePath);
  60.  
  61. var settings = {
  62. "async": true,
  63. "crossDomain": true,
  64. "url": "http://api-test.cubereum.com/fileupload/uploadfile",
  65. "method": "POST",
  66. "headers": {
  67. "Content-Type": "application/x-www-form-urlencoded",
  68. "Cache-Control": "no-cache",
  69. "Postman-Token": "f404898e-4229-4a14-933f-51e9b05c6628"
  70. },
  71. "processData": false,
  72. "contentType": false,
  73. "mimeType": "multipart/form-data",
  74. "data": form
  75. }
  76.  
  77. $.ajax(settings).done(function (response) {
  78. console.log(response);
  79. });
  80. };
  81. </script>
  82. `);
  83. }
  84. });
Add Comment
Please, Sign In to add comment