lib/QuickBaseClient.rb in quickbase_client-1.0.21 vs lib/QuickBaseClient.rb in quickbase_client-1.0.22

- old
+ new

@@ -2194,10 +2194,28 @@ def _downLoadFile( rid, fid, vid = "0" ) downLoadFile( @dbid, rid, fid, vid ) end alias downloadFile downLoadFile alias _downloadFile _downLoadFile + # Download and save a file from a file attachment field in QuickBase. + # Use the filename parameter to override the file name from QuickBase. + def downloadAndSaveFile( dbid, rid, fid, filename = nil, vid = "0" ) + response, fileContents = downLoadFile( dbid, rid, fid, vid ) + if fileContents and fileContents.length > 0 + if filename and filename.length > 0 + Misc.save_file( filename, fileContents ) + else + record = getRecord( rid, dbid, [fid] ) + if record and record[fid] and record[fid].length > 0 + Misc.save_file( record[fid], fileContents ) + else + Misc.save_file( "#{dbid}_#{rid}_#{fid}", fileContents ) + end + end + end + end + # API_EditRecord def editRecord( dbid, rid, fvlist, disprec = nil, fform = nil, ignoreError = nil, update_id = nil, msInUTC =nil, key = nil ) @dbid, @rid, @fvlist, @disprec, @fform, @ignoreError, @update_id, @msInUTC, @key = dbid, rid, fvlist, disprec, fform, ignoreError, update_id, msInUTC, key setFieldValues( fvlist, false ) if fvlist.is_a?(Hash) @@ -4523,9 +4541,26 @@ # e.g. uploadFile( "dhnju5y7", "contacts.txt", "Contacts File", { "Notes" => "#{Time.now}" } def uploadFile( dbid, filename, fileAttachmentFieldName, additionalFieldsToSet = nil ) if dbid and filename and fileAttachmentFieldName clearFieldValuePairList addFieldValuePair( fileAttachmentFieldName, nil, filename, nil ) + if additionalFieldsToSet and additionalFieldsToSet.is_a?( Hash ) + additionalFieldsToSet.each{ |fieldName,fieldValue| + addFieldValuePair( fieldName, nil, nil, fieldValue ) + } + end + return addRecord( dbid, @fvlist ) + end + nil + end + + # Add a File Attachment into a new record in a table, using a string containing the file contents. + # Additional field values can optionally be set. + # e.g. uploadFile( "dhnju5y7", "contacts.txt", "fred: 1-222-333-4444", "Contacts File", { "Notes" => "#{Time.now}" } + def uploadFileContents( dbid, filename, fileContents, fileAttachmentFieldName, additionalFieldsToSet = nil ) + if dbid and filename and fileAttachmentFieldName + clearFieldValuePairList + addFieldValuePair( fileAttachmentFieldName, nil, filename, fileContents ) if additionalFieldsToSet and additionalFieldsToSet.is_a?( Hash ) additionalFieldsToSet.each{ |fieldName,fieldValue| addFieldValuePair( fieldName, nil, nil, fieldValue ) } end