:- ensure_loaded(common).
cvs_id('$Id: upload.pl,v 1.2 2004/10/21 18:50:04 sandro Exp $').
/*

  Ugh, this code has serious parallels to retrieve.pl which I'm
  just using cut/paste for now -- should factor out....  But this is
  quite a bit simpler too.

*/


:- ensure_loaded(library(debug)).
:- debug(upload).

/*

new_upload(_Req, UploadedData, BaseURI, Upload) :-
	
	rdfpage_gen_uri(About),
	rdfpage_sub_uri(About, upload, Upload),
	rdfpage_make_storage(About),
	
	% debug(upload, 'new Upload for ~a is ~a', [URI, Upload]),

	rdfpage_assert(Upload, rdf:type, retr:'Upload'),
	rdfpage_assert(Upload, rdfs:label, literal('An Upload')),
	rdfpage_assert(Upload, retr:baseURI, BaseURI),
	rdfpage__group_index(About, _Group, Index),
	atom_number(IndexAtom, Index),
	atom_concat('Data Page #', IndexAtom, Label),
	rdfpage_assert(About, rdfs:label, literal(Label)),
	rdfpage_assert(About, rdf:type, retr:'RDFSource'),

	get_time(StartTime),
	rdfpage_assert(Upload, retr:startTime, literal(unixtime(StartTime))),

	% rdfpage_filename(About, headers, HeadersFile),
	rdfpage_filename(About, data, DataFile),

	% check_for_errors(Upload), % throws ... something
	% add_header_metadata(Upload, HeadersFile),


	% fake it out!
	open(DataFile, write, OutStream),
	write(OutStream, UploadedData),
	close(OutStream),
	debug(upload, 'Upload stored to file ~q', [DataFile]),
	after_upload(Upload, DataFile),
	debug(upload, 'after_upload done', []),

	get_time(AllDoneTime),
	rdfpage_assert(Upload, retr:allDoneTime, literal(unixtime(AllDoneTime))),
	rdfpage_assert(Upload, rdf:type, retr:'SuccessfulUpload'),
	rdfpage_qsave(About).

*/