Flutter try catch to open file - image

I am trying to load an image and then display it. But it is possible the image is not yet existing because the user has not set it yet (in this case it is an image from assets that is displayed). I use a try/catch to see if the file is existing or not to avoid any error but the exception is never catched. Here the code I use :
void initState() {
super.initState();
widget.storage.readDirectory().then((String value) {
Image localImage;
try {
localImage = Image.file(File('$value/photoProfile.jpg'));
} catch (Exception) {
return localImage =null ;
}
setState(() {
_photoPath = localImage;
});
});
}
And the error :
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = '/data/user/0/com.example.flutterappdeepfashion/app_flutter/photoProfile.jpg' (OS Error: No such file or directory, errno = 2)
How can I solve my problem and avoid errors ?
Thank you for your help !

Is your image in the assets folder ? Because the path you are trying to access is the app cache.

Related

update profile image functionality is not working while hosting as jar

Hi I am new to Springboot I was trying to develop a application, One of its functionality is to upload profile Image. It was working fine in STS but when I pack it in jar and hosting it on AWS EC2 envirnment I am getting some error while processing that image
Error:
handler for profile picture:
#PostMapping("/process-contact")
public String processContact(#ModelAttribute Contact contact, #RequestParam("profileImage") MultipartFile file,
HttpSession session) {
try {
contact.setUser(user);
user.getContacts().add(contact);
// processing and uploading photo
if (file.isEmpty()) {
System.out.println("File is empty");
contact.setImage("contact.png");
} else {
//Processing Image
InputStream inputStream = file.getInputStream();
Path paths = Paths.get(new ClassPathResource("/static/img").getFile().getPath()+"/" +file.getOriginalFilename());
Files.copy(inputStream, paths, StandardCopyOption.REPLACE_EXISTING);
contact.setImage(file.getOriginalFilename());
}
// Success Message
session.setAttribute("message", new Message("Your contact is added...", "success"));
this.userRepository.save(user);
System.out.println("Successfully Added");
} catch (Exception E) {
E.printStackTrace();
// Failed message
session.setAttribute("message", new Message("Something went wrong "+E.getMessage(), "danger"));
}
return "normal/add_contact_form";
}
It is working fine in IDE after some research I found way of writing data in jar is diffrent could some please help me how can I implemenr it for jar also.
Thankyou
all you need to do is replace this line:
Path paths = Paths.get(new ClassPathResource("/static/img").getFile().getPath()+"/" +file.getOriginalFilename());
With:
Path paths = Paths.get(new FileSystemResource("/static/img").getFile().getPath()+"/" +file.getOriginalFilename());
THat will work like charm.

Unable to get image after reinstalling the app

I am not able to get the images stored in Parse-Server as a file, once I reinstall the app. It works fine while a user is logged in but once the app is uninstalled only files are unable to access.It shows exception saying :- File doesn't exist . And I am not able to download image in parse server as well .It will redirect me to role section.
Tried changing version of parse in gradle.
I should be able to access images after reinstalling app. And I should be able to download image in parse.
code written to upload image-----------------------
ParseFile filename = new ParseFile("name.png", Byte);
filename.saveInBackground();
classObject.put("imagePic", filename);
classObject.saveInBackground();
Retrieving from Parse server--------------
file.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if(e == null) {
if(data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,data.length);
imageView.setImageBitmap(bitmap);
}
}
});

Open Uri to read JSON file in background task UWP

I have a use case where I have to read a config.json file from an AppService and based on the configuration in json file I have to generate an ID.
I am using following piece of code to generate the Uri so that I can open the file using StorageFile.GetFileFromApplicationUriAsync(fileUri).
Uri fileUri = null;
try
{
Debug.WriteLine("Creating new uri");
fileUri = new Uri(fileName);
if (fileUri == null)
{
Debug.WriteLine("Uri creation failed");
} else
{
Debug.WriteLine("New Uri created");
}
} catch (Exception ex)
{
Debug.WriteLine("Uri creation failed" + ex.Message);
}
Now when I am trying to debug this code my debugger is disappearing after line with new Uri(fileName)
If I just let the code run with no breakpoints I am not seeing any message after Creating new uri. Not even an exception.
Value of fileName is "ms-appx:///config/config.json"
Can anyone please explain what is wrong here? Also is it possible to open and read a file from an AppService?
--
Thanks
Tarun
The uri use appx only can read the resource is content in msbuild.
You can right click the file and select the property and you should select the file's build action as content.
http://jycloud.9uads.com/web/GetObject.aspx?filekey=449e34647d61faca2ce846b773a4da8e
http://jycloud.9uads.com/web/GetObject.aspx?filekey=5423b79037eee8dc66431d0478d79871
http://jycloud.9uads.com/web/GetObject.aspx?filekey=6189eb9547c6f2fa79333df67ab33cef
You can see the last image is use complie and you can change it to content.
Sorry, my visual studio's language is local language.But the visual studio's have the same layout.

AndEngine TMX load imagelayer ERROR

10-24 10:05:24.576: E/MAP(16278): Error loading file: tmx/tess.tmx
10-24 10:05:24.576: E/MAP(16278): org.andengine.extension.tmx.util.exception.TMXLoadException: org.andengine.extension.tmx.util.exception.TMXParseException: Unexpected start tag: 'imagelayer'.
10-24 10:05:24.576: E/MAP(16278): at org.andengine.extension.tmx.TMXLoader.load(TMXLoader.java:256)
10-24 10:05:24.576: E/MAP(16278): at org.andengine.extension.tmx.TMXLoader.loadFromAsset(TMXLoader.java:213)
......
Here my code
public MainMap(Activity activity, Engine engine, String mapName) {
super();
String location = "tmx/" + mapName + ".tmx";
try {
tmxLoader = new TMXLoader(activity.getAssets(),
engine.getTextureManager(),
engine.getVertexBufferObjectManager());
this.mTMXTiledMap = tmxLoader.loadFromAsset(location);
this.mTMXTiledMap
.setIsometricDrawMethod(TMXIsometricConstants.DRAW_METHOD_ISOMETRIC_ALL);
this.mTMXLayer = this.mTMXTiledMap.getTMXLayers().get(0);
this.mTMXLayer2 =this.mTMXTiledMap.getTMXLayers().get(1);
createBlockedTile(mTMXTiledMap.getTileColumns(), mTMXTiledMap.getTileRows());
} catch (final TMXLoadException e) {
Log.e("MAP", String.format("Error loading file: %s", location), e);
}
use
this.attachChild(mainMap.getmTMXLayer());
this.attachChild(mainMap.getmTMXLayer2());
The image layer is a layer type that was added in Tiled 0.9.0. It is documented at https://github.com/bjorn/tiled/wiki/TMX-Map-Format#imagelayer.
Most likely, AndEngine has not been updated to support this layer type yet. For this you could either patch it up yourself or report an issue to the author(s) to make sure they are aware of this missing feature.
Alternatively, don't use an image layer in your map to make sure you can load it with the current version of AndEngine.

Windows Azure: Error 300 Ambiguous Redirect when creating a blob container

I followed a tutorial on creating a blob on windows azure. But when I do that, I get an exception error:
Error while creating containerThe server encountered an unknown failure: The remote server returned an error: (300) Ambiguous Redirect.
The code is:
private void SetContainersAndPermission()
{
try
{
// create a container
var CloudAccountStorage = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");
cloudBlobClient = CloudAccountStorage.CreateCloudBlobClient();
CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");
blobContainer.CreateIfNotExist();
// permissions
var containerPermissions = blobContainer.GetPermissions();
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Container;
blobContainer.SetPermissions(containerPermissions);
}
catch(Exception ex)
{
throw new Exception("Error while creating container" + ex.Message);
}
}
Can anyone tell me How to solve this problem....
I would guess the connection string is somehow wrong? Can you share the connection string? (X out your shared key...)
You could also install Fiddler (debugging HTTP proxy) and see what the HTTP request looks like. That may make the issue more obvious.
I also faced the same issue. I am not sure if this is the workaround for it. I modified the container name value in ServiceConfiguration.csfg from "Photograph" to "photograph" and it worked.
I think you can not give upper case letters in queue, table or blob name. The name should have only lower case characters.

Resources