Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. setFotoServidor(value) {
  2. isRetorno = false;
  3.  
  4. const uri = value;
  5. //const uriParts = uri.uri.toString().split('.');
  6. //const fileType = uriParts[uriParts.length - 1];
  7.  
  8. //console.log(uri);
  9. //console.log(uriParts);
  10. //console.log(fileType);
  11.  
  12. const formData = new FormData();
  13. formData.append('photo', {
  14. //consulta_id: this.state.ID_Consulta,
  15. //paciente_id: this.state.ID_Paciente,
  16. uri,
  17. //name: 'photo.' + fileType.toString(),
  18. //type: 'image/jpg',
  19. });
  20.  
  21. console.log(this.state.ID_Consulta);
  22.  
  23. var details = JSON.stringify({ "consulta_id": this.state.ID_Consulta, "paciente_id": this.state.ID_Paciente });
  24. formData.append('body', details);
  25.  
  26. console.log(formData);
  27.  
  28. fetch('http://api.brasau.com:8000/fotos', {
  29. method: 'POST',
  30. headers: {
  31. 'Authorization': 'Bearer ' + this.state.token,
  32. 'Accept': 'application/json',
  33. 'Content-Type': 'multipart/form-data',
  34. //'Content-Type': 'application/json',
  35. },
  36. body: formData,
  37. // body: JSON.stringify({
  38. // "consulta_id": this.state.ID_Consulta,
  39. // "paciente_id": this.state.ID_Paciente
  40. // }),
  41. }).then((response) => response.json())
  42. .then((responseData) => {
  43.  
  44. console.log(responseData);
  45.  
  46. var testeErro = responseData["error"];
  47.  
  48. if (testeErro != undefined) {
  49. Alert.alert(responseData["message"]);
  50. isRetorno = false;
  51. }
  52. else {
  53. isRetorno = true;
  54. }
  55. }).catch(function (error) {
  56. console.log(error);
  57. }).done();
  58.  
  59. return isRetorno;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement