Use base64 for image export/import

jokerejoker - September 7, 2009 - 10:43
Project:Node Export
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:minor
Assigned:James Andres
Status:active
Description

My idea is to use the base64- encode/decode functions with the file_get_contents and file_put_contents function to export the images.

F.eks:

export

$image = file_get_contents($file->filename);
$base = base64_encode($image);

// Some how attach base-code to the array with the file name

import

$image = base64_decode($array->filedata);

// Write the image
file_put_contents($image, $array->filename);

#1

jokerejoker - September 7, 2009 - 12:01
Version:5.x-1.x-dev» 6.x-2.x-dev

#2

danielb - September 7, 2009 - 23:42
Priority:critical» minor

#3

danielb - September 8, 2009 - 10:22
Assigned to:Anonymous» James Andres

I don't know much about the file module - perhaps this will mean more to James, but if you're able to explain your motivation a bit it might help?

#4

jokerejoker - September 9, 2009 - 20:18

With the base64 you are able to store an image as a string, and do not have to have access to the folder /tmp/store which most users don't have. How it's technically done I will refer to my previously example of how to use base64 and fetch the file data and put it back in to a new file.
BTW the $array->filename equals the filename fetch at export to put in the image data and $array->filedata equals the $base variable in the export example.

#5

James Andres - September 9, 2009 - 21:28

jokerejoker,

Hmm, I'm interested to see someone interested in this :-).

I originally considered this approach, but grew concerned about the file size of the exports. If using base64 encoded files it is not unrealistic for a node export to be a few MB in size, also base64 encoding creates 30% inflated (more bytes) data on average. To be practical, one should consider at least these aspects:

  • If the user will be able to copy the node export once it is generated (some browsers, especially on Windows, have difficulty putting large amounts of data in the clipboard)
  • The effects of performing batch exports (100 exports at 2MB a piece .... ouch)

I welcome any ideas you have on the above points!

James

#6

danielb - September 10, 2009 - 03:31

Is it possible to add the base64 method in - but it only gets used by the export if the module is configured to do so by the user?

The import would auto detect which method the pasted code is using.

#7

jokerejoker - September 10, 2009 - 08:17

I see your point with the file size, though it would be great to see this as an option, because I don't have access to the exported files at my host provider.

I think it would be great to export the files to drupal files folder, and have an option to export the files as base64.

#8

danielb - September 10, 2009 - 13:10

If it comes to it, we can add a feature to serve the entire node code as a downloadable file, and an option for an upload in the import screen.

#9

jokerejoker - September 14, 2009 - 11:06

That would be the best solution to my point of view.

#10

danielb - October 6, 2009 - 01:43

I've added the ability to have a downloadable file, which should allow export of a large number of nodes, or a small number of nodes with embedded file/image data, without the issues of having to copy a large amount of text. I hope this is sufficient to enable this issue to progress?

#11

James Andres - October 28, 2009 - 16:21

Please give this patch a test, it adds all the requested functionality. It's a fairly big change for the node_export_file module, since I have made base64 the default export option! I think it's a change for the best though.

Also, sorry for the long delay. I have been very busy with client work, like that's any excuse .. ;-).

AttachmentSize
node_export_file.base64.patch 9.3 KB
 
 

Drupal is a registered trademark of Dries Buytaert.