|
-
Mar 20th, 2003, 08:03 PM
#1
Thread Starter
Frenzied Member
Write Binary to DB and Read After to create document!
Why why i read a .jpg for example, write it in a database, then why when i read it back from the db and write it to a file, it add 26 byte and the end ?
the picture still works, but is 26 byte bigger ?
When i debug, i can see that it's in the db that the file is 26 bigger(with lngFileSize = rs.Fields("attachementSource").ActualSize), so that's why i write 26 extra byte, but why ?
tx guys!
-
Mar 20th, 2003, 09:28 PM
#2
sebs,
It's all in your code (which you failed to post). So I can not help you there. You did not mention or show how you put the data tin the db.
-
Mar 21st, 2003, 08:00 AM
#3
Thread Starter
Frenzied Member
Originally posted by randem
sebs,
It's all in your code (which you failed to post). So I can not help you there. You did not mention or show how you put the data tin the db.
Yeah, sorry, i thought i would of been a common thing for access to add extra byte in the OLE Field!
here my code that save it in the DB
VB Code:
fSize = FileLen(docAttachements(0, X))
strSource = Space(fSize)
ReDim bytData(intChunk)
Open docAttachements(0, X) For Binary As freeF
rs.Open "SELECT * FROM tblAttachements WHERE attachementId=0", conn, adOpenDynamic, adLockPessimistic
rs.AddNew
rs!attachementQueueId = newId
rs!attachementName = docAttachements(0, X)
lngCurr = 0
While lngCurr < fSize
If lngCurr + intChunk >= fSize Then ReDim bytData(intChunk)
Get #freeF, , bytData
lngCurr = lngCurr + intChunk
rs.Fields("attachementSource").AppendChunk bytData
Wend
Close #freeF
tx
-
Mar 21st, 2003, 10:55 AM
#4
sebs,
One problem that I see is with intChunk, It never seems to change yet you use it to write data to the db. In most cases intChunk should change at least once on a large file (the last write to the file), It should get smaller to accommondate for the last part of the file that does not fill the buffer.
VB Code:
If lngCurr + intChunk >= fSize Then ReDim bytData(intChunk)
should read
If lngCurr + intChunk >= fSize Then
intChunk = fSize - lngCurr
ReDim bytData(intChunk)
End If
The 26 bytes that you refer to is probably a difference of the last buffer in the file and the actual buffer you use to read the file into.
-
Mar 21st, 2003, 11:01 AM
#5
Thread Starter
Frenzied Member
tx for the reply randem,
i use intChunk to increment my cursor(lngCursor)
i use the size of bytData to read from the file and write to the db!!
what do you think?
i don't think that intChunk = fSize - lngCurr will fix my problem!
-
Mar 21st, 2003, 11:06 AM
#6
Thread Starter
Frenzied Member
oh and i'm sorry, because my good version is at home!
i actually had If lngCurr + intChunk >= fSize Then ReDim bytData(fSize - lngCurr)
i thought that i would of fix the problem but it only reduce the the space by a little!
-
Mar 21st, 2003, 11:16 AM
#7
sebs,
Why are you incrementing intChunk and what has that to do with the db cursor? intChunk should stay constant and you should not be messing with the db cursor at all (if that's what you mean).
-
Mar 21st, 2003, 11:18 AM
#8
Thread Starter
Frenzied Member
no i mean!
lngCursor is my counter, and i increment it by intChunk !
i don't touch the DB cursor !
-
Mar 21st, 2003, 11:51 AM
#9
sebs,
Then there are only two other things that could be going wrong. One is the type of field you are using to write to and the database that you are using. What are they?
Debug the write and check:
1) Check after each write to the db what the db has for a fieldsize.
2) Check your last buffer size and counts to see if the check out with each other.
-
Mar 21st, 2003, 12:09 PM
#10
Thread Starter
Frenzied Member
tx for the reply, again!
AS for the Field type, it's OLE Object Field, is that ok ? Shoud it be Memo ?
and for the field size, everything seem to be fine, i added a watched to my program to debug, and everythin look alright!
i event tried bytData(fSize - lngCurr-26) and still add the extra bytes!!
do you know if it's an Access thing ?
tx again, i appreciate your help
-
Mar 21st, 2003, 12:18 PM
#11
sebs,
The problem is with your OLE Object field. Basically those bytes probably tell the application the correct program to use to open the document. You should be using the Memo field. In other databases the type of field you use would be totally different.
Use the Memo field an all you problems will go away (well, the one discussed here will).
-
Mar 21st, 2003, 12:22 PM
#12
Thread Starter
Frenzied Member
ok, but rs.Fields("attachementSource").AppendChunk bytData does'nt seem to work!!
should I read all the file, put it in a string or byte array then write it to the memo field ?
-
Mar 21st, 2003, 12:50 PM
#13
sebs,
What error are you getting? I remember you can use Ole Object also if you remeber to account for UniCode. Probably better for binary data anyway.
use the format:
VB Code:
dbTable.Fields(i).AppendChunk (Chunk())
or
dbTable!Data.AppendChunk Chunk()
This might help also:
Select Case UniCode
Case True
Buffer = snpTable.Fields(i).GetChunk(ChunkSize)
For k = 1 To ChunkSize
Chunk(k - 1) = Asc(Mid(Buffer, k, 1))
Next k
Case Else
Chunk() = snpTable.Fields(i).GetChunk(ChunkSize)
End Select
this works on an OLE Object Field.
-
Mar 21st, 2003, 12:57 PM
#14
Thread Starter
Frenzied Member
alright, tx a lot , i'll try that later
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|