You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2022/12/29 11:58:05 UTC

[GitHub] [cordova-plugin-file] realtebo opened a new issue, #552: @7.0.0 - GET http:///__cdvfile_temporary__/ failed

realtebo opened a new issue, #552:
URL: https://github.com/apache/cordova-plugin-file/issues/552

   # Bug Report
   
   ## Problem
   
   I'm using fileEntry.toLocalURL() to find where is placed a downloaded image, so I can show it to the user.
   
   I'm using this path as img src.
   
   ### What is expected to happen?
   
   Image is loaded from device as showed to the user
   
   ### What does actually happen?
   
   I got a 404
   
   ## Information
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   
   The nativeUrl of the file is `file:///data/user/0/it.realtebo.offline/cache/0.jpg` 
   
   I verified with adb shell that file exists and is readable from my app 
   
   The .toInternaURL() and the  .toURL() gives me same path: `http://192.168.56.1:9400/__cdvfile_temporary__/0.jpg`
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   
   Having already a `fs` which is a `DirectoryEntry` obtained as 
   
   ```
   window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
   
   }
   ```
   
   And having `image` as an object containing a `imageUrl` to download, I use this code to save the file to storage
   
   This portion works well. I have files succesfully saved said before.
   
   ```
   / Scarico l'immagine
     let imageUrl = image.download_url;
     console.log("Scarico il file " + imageUrl);
   
     const {
       data: imageData,
       error: imageError,
       statusCode: imageStatusCode,
     } = await useFetch(imageUrl).get().blob();
   
     if (imageStatusCode.value == 404) {
       // console.log("Immagine non trovata: " + imageUrl, imageStatusCode.value);
       return;
     }
   
     if (imageError.value) {
       // console.log("imageError ", imageError.value);
       return;
     }
   
     // Posso proseguire col salvataggio su disco
     // console.log("Immagine scaricata");
   
     // Salvo su file l'immagine appena scaricata
     fs.root.getFile(
       path,
       { create: true },
       // file creato con successo
       function (newFileEntry) {
         console.log("Ho creato il file", newFileEntry);
   
         newFileEntry.createWriter(function (newFileWriter) {
           newFileWriter.onwriteend = function () {
             console.log("Successful file write...");
           };
   
           newFileWriter.onerror = function (e) {
             console.log("Failed file write: " + e.toString());
           };
   
           newFileWriter.write(imageData.value);
           localFileUrls[image.id] = getImageSource(newFileEntry);
         });
       },
       // file non creato per un altro errore, damn
       function (newFileError) {
         console.log("Errore in fase di creazione del nuovo file", newFileError);
       }
     );
   ```
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   
   I am on Android 11, on an Emulated Pixel Phone 
   
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   
   cordova version: 11.'
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [X] I searched for existing GitHub issues
   - [X] I updated all Cordova tooling to most recent version
   - [X] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] jthrilly commented on issue #552: @7.0.0 - GET http:///__cdvfile_temporary__/ failed

Posted by "jthrilly (via GitHub)" <gi...@apache.org>.
jthrilly commented on issue #552:
URL: https://github.com/apache/cordova-plugin-file/issues/552#issuecomment-1635600754

   This worked for me, when I came across the same issue. 
   
   I load HTML from a specific IP address on a specific port when I am doing development, to get a hotreload environment. 
   
   Before I write a check for this that does a string replace, is there a better way of handling this use case? Could `toURL() ` not always return `http://localhost`, since this is always required by `WebViewAssetLoader` (which seems to be the only use-case for `toURL()` anyway...). Thoughts?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] lovelyelfpop commented on issue #552: @7.0.0 - GET http:///__cdvfile_temporary__/ failed

Posted by "lovelyelfpop (via GitHub)" <gi...@apache.org>.
lovelyelfpop commented on issue #552:
URL: https://github.com/apache/cordova-plugin-file/issues/552#issuecomment-1635360512

   I suppose you are loading a html from http://192.168.56.1:9400/
   `http://192.168.56.1:9400/__cdvfile_temporary__/0.jpg` will not be intercepted by `WebViewAssetLoader`, you should replace the origin to `localhost` (`http://localhost/__cdvfile_temporary__/0.jpg`), then the `<img>` node will display the image


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


[GitHub] [cordova-plugin-file] jthrilly commented on issue #552: @7.0.0 - GET http:///__cdvfile_temporary__/ failed

Posted by "jthrilly (via GitHub)" <gi...@apache.org>.
jthrilly commented on issue #552:
URL: https://github.com/apache/cordova-plugin-file/issues/552#issuecomment-1635617304

   In case it is useful to anyone, a neat (and quick) way of replacing the required parameters without needing to faff with a regex is:
   
   ```
           const fileURL = await resolveLocalFilesystemURL(fileEntry);
   
           if (process.env.NODE_ENV === 'development') { // Whatever runtime env detection you need
             const url = new URL(fileURL);
             url.host = 'localhost';
             url.port = '';
             return url.toString();
           }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org