Saving Photo to app and filename to table to display later from the table

In my app I have it so the user can enter in a recipe name, picture and other things and then save it to the app. It saves it a table for the recipe. I so far have been able to save the text the user enters in and it bring it back up in another view in the app, but I am struggling to get it to work with the photo.  I have it so the user can select the picture and import it into the app and to save the photo with a custom name but I can’t seem to be able to bring it back up again later to display in the app later. I am storing the photos/photo location in a table. I think my picture somehow gets lost or I don’t have the write filename to access it or something. My picture is saved to the app with its updated name. I can’t seem to get it to display again though.

------Function to save table inside a table--- local function saveRecipeTableToDinnerTable(recipeTable) table.insert(dinnerRecipes,recipeTable) loadsave.saveTable(dinnerRecipes,"recipeData") end -------Function to get the photo and save it to a table---- local function addPhotoOnComplete(event) if (event.completed) then local insertedPhoto=event.target loadsave.loadTable("recipeTable" ) local pictureName={recipeTable.name,".jpg"} media.save(pictureName,system.DocumentsDirectory) local tablePicString={picture=pictureName} local photoNameInsertTable=tablePicString table.insert(recipeTable,photoNameInsertTable) saveRecipeTableToDinnerTable(recipeTable) fitImage(insertedPhoto,400,600) insertedPhoto:translate(100, 400) sceneGroup:insert(insertedPhoto) scrollView:insert(insertedPhoto) local testPic=display.newImageRect(dinnerRecipes[5].picture,system.DocumentsDirectory,400,600) end end ----------------------------------------------------------------------------------------- --------photoListener----------------------------------------------------------- local function addPhotoListener (event) if media.hasSource( media.PhotoLibrary ) then loadsave.loadTable("recipeTable" ) media.selectPhoto( { mediaSource=media.PhotoLibrary, listener = addPhotoOnComplete --destination={baseDir=system.DocumentsDirectory, --filename=recipeTable.name,".jpg"} } ) --media.save("test.jpg",system.DocumentsDirectory) else native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end end -------------------------------------------------------------------------------- --------photoListener----------------------------------------------------------- local function addPhotoListener (event) if media.hasSource( media.PhotoLibrary ) then loadsave.loadTable("recipeTable" ) media.selectPhoto( { mediaSource=media.PhotoLibrary, listener = addPhotoOnComplete --destination={baseDir=system.DocumentsDirectory, --filename=recipeTable.name,".jpg"} } ) --------------------------------------Where I am displaying later----- for i=1, #dinnerRecipes do recipePicture[i] = widget.newButton( { width = 640, height = 300, defaultFile = dinnerRecipes[i].picture,system.DocumentsDirectory or system.ResourceDirectory, id = i, onEvent = goToThisRecipe} ) recipePicture[i]:translate(0, ((i\*tvy)-100)) scrollView:insert(recipePicture[i]) local imageMask=display.newImageRect("darkerMask.png", 640,300) imageMask:translate(320, ((i\*tvy)+50)) scrollView:insert(imageMask) recipeText[i] = display.newText(dinnerRecipes[i].name,320,100,native.systemFontBold,60) recipeText[i]:translate(0,((i\*tvy)-50)) recipeText[i]:setFillColor( 1, 1, 1 ) recipeText[i]:toFront() scrollView:insert(recipeText[i]) print(dinnerRecipes[i].name) end

The table that is saved, that stores the information is

[{“picture”:“tacoSaladPic.png”,“variations”:“Will enter later fishtaco variable”,“recipe”:"1 Cook Hamburger 2 Put chips in … 3… ",“name”:“Taco Salad”,“prepTime”:“20min”,“rating”:3,“cookTime”:“20min”},{“picture”:“hamburger.png”,“variations”:“Will enter later fishtaco variable”,“recipe”:“1 Take ground hamburger and put into patties… 2 Get Bunns…”,“name”:“Hamburger”,“prepTime”:“10 Minutes”,“holiday”:“4th of July”,“cookTime”:“30min”,“ratings”:4},{“picture”:“barnyardBiscuits.jpg”,“variations”:“Will enter later fishtaco variable”,“preptTime”:“20min”,“recipe”:“1 Thaw biscuits 2 put seasoning in hamburger 3… 4…”,“name”:“Barnyard Biscuits”,“rating”:5,“cookTime”:“10min”},{“name”:“Sloppy Joes”,“picture”:“sloppyJoes.jpg”}]

In the simulator it doesn’t supporting photos so it doesn’t go into the saving the function and then doesn’t save the the updated table. I have built the app and ran it and all that showed up was the text entered in. 

formatyourcode.jpg

What does the JSON table look like after you save it?

If it isn’t too big, you can paste that as code too.

  1. File -> Show Project Sandbox
  2. Look in ‘Documents’ folder.

formatyourcode.jpg

What does the JSON table look like after you save it?

If it isn’t too big, you can paste that as code too.

  1. File -> Show Project Sandbox
  2. Look in ‘Documents’ folder.