Fetching a binary document from BaseX with C# using the server API
Tuesday, 30 December 2014 · 3 messages · last reply 6 Jan 2015
BB
Boxstart, Bjorn30 Dec 2014 16:40 #
Hello,
I'm currently working on the integration of BaseX in part of our .Net based software. One part of the functionality will be to store and retrieve binary files. I haven't been able to retrieve the raw files from the server yet using C#. I based my solution on the example of the C# client in the source code repository of BaseX. With my current solution I receive only the first few (3 to 7) bytes of the file (at least I think they are...).
The code I have at the moment is:
/// <summary>
/// Retrieves a RAW document from the database. The database must be opened before executing this command.
/// </summary>
/// <param name="path">The path to the binary data to be retrieved</param>
/// <returns>A byte array with the binary data</returns>
public byte[] Retrieve(string path)
{
//stream.WriteByte((byte)BaseXCommand.QUERY);
Send("RETRIEVE " + path);
//Send(path);
using (MemoryStream ms = new MemoryStream())
{
Receive(ms);
info = Receive();
if (!Ok())
{
throw new IOException(info);
}
return ms.ToArray();
}
}Can anybody please tell me what the problem with this solution can be or give me a hint for a correct way to retrieve the raw bytes? I know I can use the files on disk directly, but would rather not go that way.
Thanks in advance for your reaction!
Kind regards,
Björn Boxstart
CG
Christian Grün6 Jan 2015 11:42 #
Hi Björn,
sorry for letting you wait. I have just updated the C# code [1] (see [2] for more details). Could you give it another try?
Thanks,
Christian
PS: We are looking for users who help us to update the client bindings to the new 8.0 authentication. It should be fairly easy to realize; if you may be interested, please tell me!
[1] https://github.com/BaseXdb/basex/commit/d49901c022117d5ae9a014f67a1e214fa82a19c9 [2] http://docs.basex.org/wiki/Server_Protocol#Transfer_Protocol
Quoted text · Bjorn · 84 lines
On Tue, Dec 30, 2014 at 3:40 PM, Boxstart, Bjorn <Bjorn_Boxstart at reyrey.com> wrote: > Hello, > > > > I’m currently working on the integration of BaseX in part of our .Net based > software. One part of the functionality will be to store and retrieve binary > files. I haven’t been able to retrieve the raw files from the server yet > using C#. I based my solution on the example of the C# client in the source > code repository of BaseX. With my current solution I receive only the first > few (3 to 7) bytes of the file (at least I think they are…). > > > > The code I have at the moment is: > > > > /// <summary> > > /// Retrieves a RAW document from the database. The database must be > opened before executing this command. > > /// </summary> > > /// <param name="path">The path to the binary data to be > retrieved</param> > > /// <returns>A byte array with the binary data</returns> > > public byte[] Retrieve(string path) > > { > > //stream.WriteByte((byte)BaseXCommand.QUERY); > > Send("RETRIEVE " + path); > > //Send(path); > > > > using (MemoryStream ms = new MemoryStream()) > > { > > Receive(ms); > > info = Receive(); > > if (!Ok()) > > { > > throw new IOException(info); > > } > > return ms.ToArray(); > > } > > } > > > > Can anybody please tell me what the problem with this solution can be or > give me a hint for a correct way to retrieve the raw bytes? I know I can use > the files on disk directly, but would rather not go that way. > > > > Thanks in advance for your reaction! > > > > Kind regards, > > > > Björn Boxstart > >
BB
Boxstart, Bjorn6 Jan 2015 13:50 #
Hello Christian,
Thanks a lot for the modification. This works like a charm! I will take a look at the 8.0 authentication and give you a reply when I would like to start working on this.
Kind regards,
Björn Boxstart
-----Oorspronkelijk bericht-----
Quoted text · Christian Grün · 95 lines
Van: Christian Grün [mailto:christian.gruen at gmail.com] Verzonden: dinsdag 6 januari 2015 11:43 Aan: Boxstart, Bjorn CC: basex-talk at mailman.uni-konstanz.de Onderwerp: Re: [basex-talk] Fetching a binary document from BaseX with C# using the server API Hi Björn, sorry for letting you wait. I have just updated the C# code [1] (see [2] for more details). Could you give it another try? Thanks, Christian PS: We are looking for users who help us to update the client bindings to the new 8.0 authentication. It should be fairly easy to realize; if you may be interested, please tell me! [1] https://github.com/BaseXdb/basex/commit/d49901c022117d5ae9a014f67a1e214fa82a19c9 [2] http://docs.basex.org/wiki/Server_Protocol#Transfer_Protocol On Tue, Dec 30, 2014 at 3:40 PM, Boxstart, Bjorn <Bjorn_Boxstart at reyrey.com> wrote: > Hello, > > > > I’m currently working on the integration of BaseX in part of our .Net > based software. One part of the functionality will be to store and > retrieve binary files. I haven’t been able to retrieve the raw files > from the server yet using C#. I based my solution on the example of > the C# client in the source code repository of BaseX. With my current > solution I receive only the first few (3 to 7) bytes of the file (at least I think they are…). > > > > The code I have at the moment is: > > > > /// <summary> > > /// Retrieves a RAW document from the database. The database > must be opened before executing this command. > > /// </summary> > > /// <param name="path">The path to the binary data to be > retrieved</param> > > /// <returns>A byte array with the binary data</returns> > > public byte[] Retrieve(string path) > > { > > //stream.WriteByte((byte)BaseXCommand.QUERY); > > Send("RETRIEVE " + path); > > //Send(path); > > > > using (MemoryStream ms = new MemoryStream()) > > { > > Receive(ms); > > info = Receive(); > > if (!Ok()) > > { > > throw new IOException(info); > > } > > return ms.ToArray(); > > } > > } > > > > Can anybody please tell me what the problem with this solution can be > or give me a hint for a correct way to retrieve the raw bytes? I know > I can use the files on disk directly, but would rather not go that way. > > > > Thanks in advance for your reaction! > > > > Kind regards, > > > > Björn Boxstart > >
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery