@@ -111,6 +111,7 @@ def __build_packet_payload(self,
111111 file_name : str = None ,
112112 blob_path : str = None ,
113113 parent_file_id : int = None ,
114+ text_data : str = None ,
114115 ordinal : int = 0 ):
115116 packet = {'media' : {}}
116117 packet ['media' ]['url' ] = url
@@ -119,6 +120,7 @@ def __build_packet_payload(self,
119120 # Existing Instances
120121 packet ['frame_packet_map' ] = frame_packet_map
121122 packet ['ordinal' ] = ordinal
123+ packet ['text_data' ] = text_data
122124 packet ['type' ] = type
123125 packet ['connection_id' ] = connection_id
124126 packet ['parent_file_id' ] = parent_file_id
@@ -173,12 +175,50 @@ def from_blob_path(self,
173175 file_name = name ,
174176 directory_id = directory_id ,
175177 type = "from_blob_path" ,
176- parent_file_id = parent_file_id ,
178+ parent_file_id = parent_file_id ,
177179 ordinal = ordinal
178180 )
179181 self .from_packet (packet = packet )
180182 return True
181183
184+ def from_text_data (self ,
185+ file_name : str ,
186+ text_data : str ,
187+ media_type : str = 'text' ,
188+ instance_list : list = None ,
189+ frame_packet_map : dict = None ,
190+ parent_file_id : int = None ,
191+ directory_id : int = None ,
192+ ordinal : int = 0 ):
193+ """
194+ Add the given text as a text File in Diffgram
195+ :param text_data: the raw text to create the text file from.
196+ :param media_type:
197+ :param instance_list:
198+ :param frame_packet_map:
199+ :param parent_file_id: the parent file ID (for compound files)
200+ :param ordinal: the ordinal for the child file (for compound files)
201+ :return:
202+ """
203+ if self .client .default_directory is None and directory_id is None :
204+ raise Exception ("Directory not set. call set_default_directory() to set upload directory." )
205+ if directory_id is None :
206+ directory_id = self .client .directory_id
207+ name = file_name
208+ packet = self .__build_packet_payload (
209+ media_type = media_type ,
210+ instance_list = instance_list ,
211+ frame_packet_map = frame_packet_map ,
212+ file_name = name ,
213+ directory_id = directory_id ,
214+ type = "from_text_data" ,
215+ parent_file_id = parent_file_id ,
216+ ordinal = ordinal ,
217+ text_data = text_data
218+ )
219+ self .from_packet (packet = packet )
220+ return True
221+
182222 def from_url (
183223 self ,
184224 url : str ,
0 commit comments