Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-28-2008, 12:52 PM   #1
HW2002
Registered User
 
Join Date: Jan 2007
Posts: 85
Default save bytes inside database

hi,

i wonder how i can save bytes inside database?

I load image using urlstream and i want to save image source inside database?

regards,
hw2002
HW2002 is offline   Reply With Quote
Old 07-28-2008, 07:28 PM   #2
evride
2006 Man Of The Year
 
evride's Avatar
 
Join Date: Mar 2007
Posts: 919
Default

why would you do that? why not just store the file in the ApplicationStorageDirectory? then you can store the link to the file in a local database.

but if you really must store it in a database for some odd reason, then use the Base64 class to encode the image's byte data to base64 then you can store it in the database.
__________________
As long as people believe in absurdities they will continue to commit atrocities. --Voltaire
evride is offline   Reply With Quote
Old 07-28-2008, 08:43 PM   #3
HW2002
Registered User
 
Join Date: Jan 2007
Posts: 85
Default

Quote:
Originally Posted by evdog View Post
why would you do that? why not just store the file in the ApplicationStorageDirectory? then you can store the link to the file in a local database.

but if you really must store it in a database for some odd reason, then use the Base64 class to encode the image's byte data to base64 then you can store it in the database.
I need to secure/hide the images, so the user cannot find them just as regular files.

Do you have any example how to get the image byte data to base64?

_urlStream.readbyte() ?

Any url or tutorial would also be great

Thanks for help.
HW2002 is offline   Reply With Quote
Old 07-28-2008, 09:11 PM   #4
evride
2006 Man Of The Year
 
evride's Avatar
 
Join Date: Mar 2007
Posts: 919
Default

well, your method of hiding the files is not completely secure. There are sqlite admin apps that can open up the SQLite database and view all entries, no matter what file extension you give it. They could open the database, decode the Base64 code and create an image from that. So your method is security through obscurity and will not protect your images 100% though I think it will be good enough for 99% of people.


Download the Base64 class here and put it with the rest of your class files.
I have never used the urlStream class so, I hope you know what you are doing there.
Anyways, read the streamed data into a ByteArray and then encode to Base64 using the Base64.encodeByteArray() method.
ActionScript Code:
var ba:ByteArray = new ByteArray(); //read the urlStream data into the byteArray. leaving that part out here var base64String:String = Base64.encodeByteArray(ba); //insert base64String into the database

then put this in an sqlite database. i hope you know how to do this part, if not i can help you with that as well.

to retrieve the stored data you would load the data from the sqlite database and decode the string into a bytearray.
__________________
As long as people believe in absurdities they will continue to commit atrocities. --Voltaire
evride is offline   Reply With Quote
Old 07-29-2008, 06:07 AM   #5
HW2002
Registered User
 
Join Date: Jan 2007
Posts: 85
Default

Quote:
Originally Posted by evdog View Post
well, your method of hiding the files is not completely secure. There are sqlite admin apps that can open up the SQLite database and view all entries, no matter what file extension you give it. They could open the database, decode the Base64 code and create an image from that. So your method is security through obscurity and will not protect your images 100% though I think it will be good enough for 99% of people.


Download the Base64 class here and put it with the rest of your class files.
I have never used the urlStream class so, I hope you know what you are doing there.
Anyways, read the streamed data into a ByteArray and then encode to Base64 using the Base64.encodeByteArray() method.
ActionScript Code:
var ba:ByteArray = new ByteArray(); //read the urlStream data into the byteArray. leaving that part out here var base64String:String = Base64.encodeByteArray(ba); //insert base64String into the database

then put this in an sqlite database. i hope you know how to do this part, if not i can help you with that as well.

to retrieve the stored data you would load the data from the sqlite database and decode the string into a bytearray.
thank you very much...

do you have any other methods to secure the images?

maybe encrypt the bytearray using hashkey?
HW2002 is offline   Reply With Quote
Old 07-29-2008, 06:17 AM   #6
evride
2006 Man Of The Year
 
evride's Avatar
 
Join Date: Mar 2007
Posts: 919
Default

there are encryption classes out there but i haven't played with them enough to help you on that.

http://code.google.com/p/as3crypto/
__________________
As long as people believe in absurdities they will continue to commit atrocities. --Voltaire
evride is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Unload SWF" when loading with Loader()? bjornbjorn ActionScript 3.0 4 11-02-2010 11:26 AM
unexplained large swf size tcox ActionScript 2.0 18 08-22-2007 09:35 AM
XMLSocket.onData and UTF-8 zero bytes Voetsjoeba ActionScript 1.0 (and below) 1 08-07-2007 01:19 PM
flash-application save and load KingPhantom ActionScript 2.0 15 01-12-2006 02:38 PM
Time to reboot the server??? CyanBlue General Chat 29 05-28-2003 04:21 AM


All times are GMT. The time now is 07:29 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.